diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts
index c93d5d783d453..fa40f81e809b9 100644
--- a/packages/astro/src/@types/astro.ts
+++ b/packages/astro/src/@types/astro.ts
@@ -257,7 +257,7 @@ export interface AstroGlobal<
* }
* ```
*/
- reroute: AstroSharedContext['reroute'];
+ rewrite: AstroSharedContext['rewrite'];
/**
* The element allows a component to reference itself recursively.
*
@@ -1933,19 +1933,19 @@ export interface AstroUserConfig {
/**
* @docs
- * @name experimental.rerouting
+ * @name experimental.rewriting
* @type {boolean}
* @default `false`
* @version 4.8.0
* @description
*
- * Enables the use of rerouting features in Astro pages, Endpoints and Astro middleware:
+ * Enables the use of rewriting features in Astro pages, Endpoints and Astro middleware:
*
* ```astro
* ---
* // src/pages/dashboard.astro
* if (!Astro.props.allowed) {
- * return Astro.reroute("/")
+ * return Astro.rewrite("/")
* }
* ---
* ```
@@ -1954,7 +1954,7 @@ export interface AstroUserConfig {
* // src/pages/api.js
* export function GET(ctx) {
* if (!ctx.locals.allowed) {
- * return ctx.reroute("/")
+ * return ctx.rewrite("/")
* }
* }
* ```
@@ -1969,7 +1969,7 @@ export interface AstroUserConfig {
* }
* ```
*/
- rerouting: boolean;
+ rewriting: boolean;
};
}
@@ -2543,7 +2543,7 @@ interface AstroSharedContext<
* }
* ```
*/
- reroute(reroutePayload: ReroutePayload): Promise;
+ rewrite(rewritePayload: RewritePayload): Promise;
/**
* Object accessed via Astro middleware
@@ -2672,7 +2672,7 @@ export interface APIContext<
* }
* ```
*/
- reroute: AstroSharedContext['reroute'];
+ rewrite: AstroSharedContext['rewrite'];
/**
* An object that middlewares can use to store extra information related to the request.
@@ -2866,9 +2866,9 @@ export interface AstroIntegration {
};
}
-export type ReroutePayload = string | URL | Request;
+export type RewritePayload = string | URL | Request;
-export type MiddlewareNext = (reroutePayload?: ReroutePayload) => Promise;
+export type MiddlewareNext = (reroutePayload?: RewritePayload) => Promise;
export type MiddlewareHandler = (
context: APIContext,
next: MiddlewareNext
diff --git a/packages/astro/src/core/app/pipeline.ts b/packages/astro/src/core/app/pipeline.ts
index 97784dc962ef9..cceecab49acda 100644
--- a/packages/astro/src/core/app/pipeline.ts
+++ b/packages/astro/src/core/app/pipeline.ts
@@ -4,7 +4,7 @@ import type {
SSRElement,
SSRResult,
ComponentInstance,
- ReroutePayload,
+ RewritePayload,
} from '../../@types/astro.js';
import { Pipeline } from '../base-pipeline.js';
import { DEFAULT_404_COMPONENT } from '../constants.js';
@@ -71,7 +71,7 @@ export class AppPipeline extends Pipeline {
return module.page();
}
- async tryReroute(payload: ReroutePayload): Promise<[RouteData, ComponentInstance]> {
+ async tryRewrite(payload: RewritePayload): Promise<[RouteData, ComponentInstance]> {
let foundRoute;
for (const route of this.#manifestData!.routes) {
diff --git a/packages/astro/src/core/app/types.ts b/packages/astro/src/core/app/types.ts
index 6b327fd6fefae..30134252ef9d1 100644
--- a/packages/astro/src/core/app/types.ts
+++ b/packages/astro/src/core/app/types.ts
@@ -66,7 +66,7 @@ export type SSRManifest = {
middleware: MiddlewareHandler;
checkOrigin: boolean;
// TODO: remove once the experimental flag is removed
- reroutingEnabled: boolean;
+ rewritingEnabled: boolean;
};
export type SSRManifestI18n = {
diff --git a/packages/astro/src/core/base-pipeline.ts b/packages/astro/src/core/base-pipeline.ts
index 4f6c825539957..11cff7c809f5b 100644
--- a/packages/astro/src/core/base-pipeline.ts
+++ b/packages/astro/src/core/base-pipeline.ts
@@ -1,7 +1,7 @@
import type {
ComponentInstance,
MiddlewareHandler,
- ReroutePayload,
+ RewritePayload,
RouteData,
RuntimeMode,
SSRLoadedRenderer,
@@ -69,9 +69,9 @@ export abstract class Pipeline {
*
* - if not `RouteData` is found
*
- * @param {ReroutePayload} reroutePayload
+ * @param {RewritePayload} rewritePayload
*/
- abstract tryReroute(reroutePayload: ReroutePayload): Promise<[RouteData, ComponentInstance]>;
+ abstract tryRewrite(rewritePayload: RewritePayload): Promise<[RouteData, ComponentInstance]>;
/**
* Tells the pipeline how to retrieve a component give a `RouteData`
diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts
index 13d31b3acb6ff..23563d83386c5 100644
--- a/packages/astro/src/core/build/generate.ts
+++ b/packages/astro/src/core/build/generate.ts
@@ -283,7 +283,7 @@ async function getPathsForRoute(
const label = staticPaths.length === 1 ? 'page' : 'pages';
logger.debug(
'build',
- `├── ${bold(green('✔'))} ${route.component} → ${magenta(`[${staticPaths.length} ${label}]`)}`
+ `├── ${bold(green('√'))} ${route.component} → ${magenta(`[${staticPaths.length} ${label}]`)}`
);
paths = staticPaths
@@ -556,7 +556,7 @@ function createBuildManifest(
i18n: i18nManifest,
buildFormat: settings.config.build.format,
middleware,
- reroutingEnabled: settings.config.experimental.rerouting,
+ rewritingEnabled: settings.config.experimental.rewriting,
checkOrigin: settings.config.experimental.security?.csrfProtection?.origin ?? false,
};
}
diff --git a/packages/astro/src/core/build/pipeline.ts b/packages/astro/src/core/build/pipeline.ts
index d973b24ca0e44..61f10a43465b8 100644
--- a/packages/astro/src/core/build/pipeline.ts
+++ b/packages/astro/src/core/build/pipeline.ts
@@ -1,6 +1,6 @@
import type {
ComponentInstance,
- ReroutePayload,
+ RewritePayload,
RouteData,
SSRLoadedRenderer,
SSRResult,
@@ -272,7 +272,7 @@ export class BuildPipeline extends Pipeline {
}
}
- async tryReroute(payload: ReroutePayload): Promise<[RouteData, ComponentInstance]> {
+ async tryRewrite(payload: RewritePayload): Promise<[RouteData, ComponentInstance]> {
let foundRoute: RouteData | undefined;
// options.manifest is the actual type that contains the information
for (const route of this.options.manifest.routes) {
diff --git a/packages/astro/src/core/build/plugins/plugin-manifest.ts b/packages/astro/src/core/build/plugins/plugin-manifest.ts
index e2f29920477fa..5bab9bad87e29 100644
--- a/packages/astro/src/core/build/plugins/plugin-manifest.ts
+++ b/packages/astro/src/core/build/plugins/plugin-manifest.ts
@@ -277,6 +277,6 @@ function buildManifest(
i18n: i18nManifest,
buildFormat: settings.config.build.format,
checkOrigin: settings.config.experimental.security?.csrfProtection?.origin ?? false,
- reroutingEnabled: settings.config.experimental.rerouting,
+ rewritingEnabled: settings.config.experimental.rewriting,
};
}
diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts
index 879589b4b87db..0fd4c58e66fda 100644
--- a/packages/astro/src/core/config/schema.ts
+++ b/packages/astro/src/core/config/schema.ts
@@ -87,7 +87,7 @@ const ASTRO_CONFIG_DEFAULTS = {
globalRoutePriority: false,
i18nDomains: false,
security: {},
- rerouting: false,
+ rewriting: false,
},
} satisfies AstroUserConfig & { server: { open: boolean } };
@@ -526,7 +526,7 @@ export const AstroConfigSchema = z.object({
.optional()
.default(ASTRO_CONFIG_DEFAULTS.experimental.security),
i18nDomains: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.i18nDomains),
- rerouting: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.rerouting),
+ rewriting: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.rewriting),
})
.strict(
`Invalid or outdated experimental feature.\nCheck for incorrect spelling or outdated Astro version.\nSee https://docs.astro.build/en/reference/configuration-reference/#experimental-flags for a list of all current experiments.`
diff --git a/packages/astro/src/core/middleware/callMiddleware.ts b/packages/astro/src/core/middleware/callMiddleware.ts
index baf3c0b3ef5a7..a6e8012e84c01 100644
--- a/packages/astro/src/core/middleware/callMiddleware.ts
+++ b/packages/astro/src/core/middleware/callMiddleware.ts
@@ -2,7 +2,7 @@ import type {
APIContext,
MiddlewareHandler,
MiddlewareNext,
- ReroutePayload,
+ RewritePayload,
} from '../../@types/astro.js';
import { AstroError, AstroErrorData } from '../errors/index.js';
import type { Logger } from '../logger/core.js';
@@ -46,7 +46,7 @@ export async function callMiddleware(
apiContext: APIContext,
responseFunction: (
apiContext: APIContext,
- reroutePayload?: ReroutePayload
+ reroutePayload?: RewritePayload
) => Promise | Response,
// TODO: remove these two arguments once rerouting goes out of experimental
enableRerouting: boolean,
diff --git a/packages/astro/src/core/middleware/index.ts b/packages/astro/src/core/middleware/index.ts
index cabbbc9cb9b39..17c206d6e9f54 100644
--- a/packages/astro/src/core/middleware/index.ts
+++ b/packages/astro/src/core/middleware/index.ts
@@ -1,4 +1,4 @@
-import type { APIContext, MiddlewareHandler, Params, ReroutePayload } from '../../@types/astro.js';
+import type { APIContext, MiddlewareHandler, Params, RewritePayload } from '../../@types/astro.js';
import {
computeCurrentLocale,
computePreferredLocale,
@@ -47,7 +47,7 @@ function createContext({
const route = url.pathname;
// TODO verify that this function works in an edge middleware environment
- const reroute = (_reroutePayload: ReroutePayload) => {
+ const reroute = (_reroutePayload: RewritePayload) => {
// return dummy response
return Promise.resolve(new Response(null));
};
@@ -59,7 +59,7 @@ function createContext({
site: undefined,
generator: `Astro v${ASTRO_VERSION}`,
props: {},
- reroute,
+ rewrite: reroute,
redirect(path, status) {
return new Response(null, {
status: status || 302,
diff --git a/packages/astro/src/core/middleware/sequence.ts b/packages/astro/src/core/middleware/sequence.ts
index 3782bc30befab..ef27d03c2cb4d 100644
--- a/packages/astro/src/core/middleware/sequence.ts
+++ b/packages/astro/src/core/middleware/sequence.ts
@@ -1,4 +1,4 @@
-import type { APIContext, MiddlewareHandler, ReroutePayload } from '../../@types/astro.js';
+import type { APIContext, MiddlewareHandler, RewritePayload } from '../../@types/astro.js';
import { defineMiddleware } from './index.js';
import { AstroCookies } from '../cookies/cookies.js';
@@ -20,7 +20,7 @@ export function sequence(...handlers: MiddlewareHandler[]): MiddlewareHandler {
/**
* This variable is used to carry the rerouting payload across middleware functions.
*/
- let carriedPayload: ReroutePayload | undefined = undefined;
+ let carriedPayload: RewritePayload | undefined = undefined;
return applyHandle(0, context);
function applyHandle(i: number, handleContext: APIContext) {
@@ -28,7 +28,7 @@ export function sequence(...handlers: MiddlewareHandler[]): MiddlewareHandler {
// @ts-expect-error
// SAFETY: Usually `next` always returns something in user land, but in `sequence` we are actually
// doing a loop over all the `next` functions, and eventually we call the last `next` that returns the `Response`.
- const result = handle(handleContext, async (payload: ReroutePayload) => {
+ const result = handle(handleContext, async (payload: RewritePayload) => {
if (i < length - 1) {
if (payload) {
let newRequest;
diff --git a/packages/astro/src/core/render-context.ts b/packages/astro/src/core/render-context.ts
index 12796f3c205e9..6ba23fb72796c 100644
--- a/packages/astro/src/core/render-context.ts
+++ b/packages/astro/src/core/render-context.ts
@@ -5,7 +5,7 @@ import type {
ComponentInstance,
MiddlewareHandler,
MiddlewareNext,
- ReroutePayload,
+ RewritePayload,
RouteData,
SSRResult,
} from '../@types/astro.js';
@@ -111,11 +111,11 @@ export class RenderContext {
statusText: 'Loop Detected',
});
}
- const lastNext = async (ctx: APIContext, payload?: ReroutePayload) => {
+ const lastNext = async (ctx: APIContext, payload?: RewritePayload) => {
if (payload) {
- if (this.pipeline.manifest.reroutingEnabled) {
+ if (this.pipeline.manifest.rewritingEnabled) {
try {
- const [routeData, component] = await pipeline.tryReroute(payload);
+ const [routeData, component] = await pipeline.tryRewrite(payload);
this.routeData = routeData;
componentInstance = component;
} catch (e) {
@@ -178,7 +178,7 @@ export class RenderContext {
middleware,
apiContext,
lastNext,
- this.pipeline.manifest.reroutingEnabled,
+ this.pipeline.manifest.rewritingEnabled,
this.pipeline.logger
);
if (response.headers.get(ROUTE_TYPE_HEADER)) {
@@ -198,10 +198,10 @@ export class RenderContext {
const redirect = (path: string, status = 302) =>
new Response(null, { status, headers: { Location: path } });
- const reroute = async (reroutePayload: ReroutePayload) => {
+ const rewrite = async (reroutePayload: RewritePayload) => {
pipeline.logger.debug('router', 'Called rerouting to:', reroutePayload);
try {
- const [routeData, component] = await pipeline.tryReroute(reroutePayload);
+ const [routeData, component] = await pipeline.tryRewrite(reroutePayload);
this.routeData = routeData;
if (reroutePayload instanceof Request) {
this.request = reroutePayload;
@@ -257,7 +257,7 @@ export class RenderContext {
},
props,
redirect,
- reroute,
+ rewrite,
request: this.request,
site: pipeline.site,
url,
@@ -385,10 +385,10 @@ export class RenderContext {
return new Response(null, { status, headers: { Location: path } });
};
- const reroute = async (reroutePayload: ReroutePayload) => {
+ const rewrite = async (reroutePayload: RewritePayload) => {
try {
pipeline.logger.debug('router', 'Calling rerouting: ', reroutePayload);
- const [routeData, component] = await pipeline.tryReroute(reroutePayload);
+ const [routeData, component] = await pipeline.tryRewrite(reroutePayload);
this.routeData = routeData;
if (reroutePayload instanceof Request) {
this.request = reroutePayload;
@@ -431,7 +431,7 @@ export class RenderContext {
},
locals,
redirect,
- reroute,
+ rewrite,
request: this.request,
response,
site: pipeline.site,
diff --git a/packages/astro/src/vite-plugin-astro-server/pipeline.ts b/packages/astro/src/vite-plugin-astro-server/pipeline.ts
index 4a85c20571e9f..1ee4d5b59194b 100644
--- a/packages/astro/src/vite-plugin-astro-server/pipeline.ts
+++ b/packages/astro/src/vite-plugin-astro-server/pipeline.ts
@@ -4,7 +4,7 @@ import type {
ComponentInstance,
DevToolbarMetadata,
ManifestData,
- ReroutePayload,
+ RewritePayload,
RouteData,
SSRElement,
SSRLoadedRenderer,
@@ -190,7 +190,7 @@ export class DevPipeline extends Pipeline {
}
}
- async tryReroute(payload: ReroutePayload): Promise<[RouteData, ComponentInstance]> {
+ async tryRewrite(payload: RewritePayload): Promise<[RouteData, ComponentInstance]> {
let foundRoute;
if (!this.manifestData) {
throw new Error('Missing manifest data');
diff --git a/packages/astro/src/vite-plugin-astro-server/plugin.ts b/packages/astro/src/vite-plugin-astro-server/plugin.ts
index 10b9ff463768e..3c6f06ee9a054 100644
--- a/packages/astro/src/vite-plugin-astro-server/plugin.ts
+++ b/packages/astro/src/vite-plugin-astro-server/plugin.ts
@@ -145,7 +145,7 @@ export function createDevelopmentManifest(settings: AstroSettings): SSRManifest
inlinedScripts: new Map(),
i18n: i18nManifest,
checkOrigin: settings.config.experimental.security?.csrfProtection?.origin ?? false,
- reroutingEnabled: settings.config.experimental.rerouting,
+ rewritingEnabled: settings.config.experimental.rewriting,
middleware(_, next) {
return next();
},
diff --git a/packages/astro/test/fixtures/reroute/astro.config.mjs b/packages/astro/test/fixtures/reroute/astro.config.mjs
index 6d20ec89a31dd..af13ef19b4772 100644
--- a/packages/astro/test/fixtures/reroute/astro.config.mjs
+++ b/packages/astro/test/fixtures/reroute/astro.config.mjs
@@ -3,7 +3,7 @@ import { defineConfig } from 'astro/config';
// https://astro.build/config
export default defineConfig({
experimental: {
- rerouting: true
+ rewriting: true
},
site: "https://example.com"
});
diff --git a/packages/astro/test/fixtures/reroute/src/middleware.js b/packages/astro/test/fixtures/reroute/src/middleware.js
index 0cf03c1d77137..4d7c2a7956c8e 100644
--- a/packages/astro/test/fixtures/reroute/src/middleware.js
+++ b/packages/astro/test/fixtures/reroute/src/middleware.js
@@ -13,7 +13,7 @@ export const second = async (context, next) => {
if (context.url.pathname.includes('/auth')) {
if (context.url.pathname.includes('/auth/dashboard')) {
contextReroute = true;
- return await context.reroute('/');
+ return await context.rewrite('/');
}
if (context.url.pathname.includes('/auth/base')) {
return await next('/');
diff --git a/packages/astro/test/fixtures/reroute/src/pages/blog/hello/index.astro b/packages/astro/test/fixtures/reroute/src/pages/blog/hello/index.astro
index 07a8544aecb15..8c38e518a7b78 100644
--- a/packages/astro/test/fixtures/reroute/src/pages/blog/hello/index.astro
+++ b/packages/astro/test/fixtures/reroute/src/pages/blog/hello/index.astro
@@ -1,5 +1,5 @@
---
-return Astro.reroute(new URL("../../", Astro.url))
+return Astro.rewrite(new URL("../../", Astro.url))
---
diff --git a/packages/astro/test/fixtures/reroute/src/pages/blog/salut/index.astro b/packages/astro/test/fixtures/reroute/src/pages/blog/salut/index.astro
index 373653afd7e09..89d35ce2564d6 100644
--- a/packages/astro/test/fixtures/reroute/src/pages/blog/salut/index.astro
+++ b/packages/astro/test/fixtures/reroute/src/pages/blog/salut/index.astro
@@ -1,5 +1,5 @@
---
-return Astro.reroute(new Request(new URL("../../", Astro.url)))
+return Astro.rewrite(new Request(new URL("../../", Astro.url)))
---
diff --git a/packages/astro/test/fixtures/reroute/src/pages/dynamic/[id].astro b/packages/astro/test/fixtures/reroute/src/pages/dynamic/[id].astro
index fc1b64fbba1a3..8d849de160bf5 100644
--- a/packages/astro/test/fixtures/reroute/src/pages/dynamic/[id].astro
+++ b/packages/astro/test/fixtures/reroute/src/pages/dynamic/[id].astro
@@ -7,7 +7,7 @@ export function getStaticPaths() {
}
-return Astro.reroute("/")
+return Astro.rewrite("/")
---
diff --git a/packages/astro/test/fixtures/reroute/src/pages/reroute.astro b/packages/astro/test/fixtures/reroute/src/pages/reroute.astro
index 8396946f144b6..dbc7a6ae628a3 100644
--- a/packages/astro/test/fixtures/reroute/src/pages/reroute.astro
+++ b/packages/astro/test/fixtures/reroute/src/pages/reroute.astro
@@ -1,5 +1,5 @@
---
-return Astro.reroute("/")
+return Astro.rewrite("/")
---
diff --git a/packages/astro/test/fixtures/reroute/src/pages/spread/[...id].astro b/packages/astro/test/fixtures/reroute/src/pages/spread/[...id].astro
index 1169380cab624..0bab88d0f7b1f 100644
--- a/packages/astro/test/fixtures/reroute/src/pages/spread/[...id].astro
+++ b/packages/astro/test/fixtures/reroute/src/pages/spread/[...id].astro
@@ -5,7 +5,7 @@ export function getStaticPaths() {
];
}
-return Astro.reroute("/")
+return Astro.rewrite("/")
---
diff --git a/packages/astro/test/reroute.test.js b/packages/astro/test/rewrite.test.js
similarity index 100%
rename from packages/astro/test/reroute.test.js
rename to packages/astro/test/rewrite.test.js