full site update
This commit is contained in:
8
node_modules/astro/dist/core/routing/3xx.d.ts
generated
vendored
Normal file
8
node_modules/astro/dist/core/routing/3xx.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
type RedirectTemplate = {
|
||||
from?: string;
|
||||
absoluteLocation: string | URL;
|
||||
status: number;
|
||||
relativeLocation: string;
|
||||
};
|
||||
export declare function redirectTemplate({ status, absoluteLocation, relativeLocation, from, }: RedirectTemplate): string;
|
||||
export {};
|
19
node_modules/astro/dist/core/routing/3xx.js
generated
vendored
Normal file
19
node_modules/astro/dist/core/routing/3xx.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
function redirectTemplate({
|
||||
status,
|
||||
absoluteLocation,
|
||||
relativeLocation,
|
||||
from
|
||||
}) {
|
||||
const delay = status === 302 ? 2 : 0;
|
||||
return `<!doctype html>
|
||||
<title>Redirecting to: ${relativeLocation}</title>
|
||||
<meta http-equiv="refresh" content="${delay};url=${relativeLocation}">
|
||||
<meta name="robots" content="noindex">
|
||||
<link rel="canonical" href="${absoluteLocation}">
|
||||
<body>
|
||||
<a href="${relativeLocation}">Redirecting ${from ? `from <code>${from}</code> ` : ""}to <code>${relativeLocation}</code></a>
|
||||
</body>`;
|
||||
}
|
||||
export {
|
||||
redirectTemplate
|
||||
};
|
6
node_modules/astro/dist/core/routing/astro-designed-error-pages.d.ts
generated
vendored
6
node_modules/astro/dist/core/routing/astro-designed-error-pages.d.ts
generated
vendored
@@ -1,5 +1,5 @@
|
||||
import type { ComponentInstance, ManifestData, RouteData } from '../../@types/astro.js';
|
||||
import type { ComponentInstance, RoutesList } from '../../types/astro.js';
|
||||
import type { RouteData } from '../../types/public/internal.js';
|
||||
export declare const DEFAULT_404_ROUTE: RouteData;
|
||||
export declare const DEFAULT_500_ROUTE: RouteData;
|
||||
export declare function ensure404Route(manifest: ManifestData): ManifestData;
|
||||
export declare function ensure404Route(manifest: RoutesList): RoutesList;
|
||||
export declare const default404Instance: ComponentInstance;
|
||||
|
23
node_modules/astro/dist/core/routing/astro-designed-error-pages.js
generated
vendored
23
node_modules/astro/dist/core/routing/astro-designed-error-pages.js
generated
vendored
@@ -1,30 +1,18 @@
|
||||
import notFoundTemplate from "../../template/4xx.js";
|
||||
import { DEFAULT_404_COMPONENT, DEFAULT_500_COMPONENT } from "../constants.js";
|
||||
import { DEFAULT_404_COMPONENT } from "../constants.js";
|
||||
const DEFAULT_404_ROUTE = {
|
||||
component: DEFAULT_404_COMPONENT,
|
||||
generate: () => "",
|
||||
params: [],
|
||||
pattern: /\/404/,
|
||||
pattern: /^\/404\/?$/,
|
||||
prerender: false,
|
||||
pathname: "/404",
|
||||
segments: [[{ content: "404", dynamic: false, spread: false }]],
|
||||
type: "page",
|
||||
route: "/404",
|
||||
fallbackRoutes: [],
|
||||
isIndex: false
|
||||
};
|
||||
const DEFAULT_500_ROUTE = {
|
||||
component: DEFAULT_500_COMPONENT,
|
||||
generate: () => "",
|
||||
params: [],
|
||||
pattern: /\/500/,
|
||||
prerender: false,
|
||||
pathname: "/500",
|
||||
segments: [[{ content: "500", dynamic: false, spread: false }]],
|
||||
type: "page",
|
||||
route: "/500",
|
||||
fallbackRoutes: [],
|
||||
isIndex: false
|
||||
isIndex: false,
|
||||
origin: "internal"
|
||||
};
|
||||
function ensure404Route(manifest) {
|
||||
if (!manifest.routes.some((route) => route.route === "/404")) {
|
||||
@@ -40,7 +28,7 @@ async function default404Page({ pathname }) {
|
||||
tabTitle: "404: Not Found",
|
||||
pathname
|
||||
}),
|
||||
{ status: 404, headers: { "Content-Type": "text/html; charset=utf-8" } }
|
||||
{ status: 404, headers: { "Content-Type": "text/html" } }
|
||||
);
|
||||
}
|
||||
default404Page.isAstroComponentFactory = true;
|
||||
@@ -49,7 +37,6 @@ const default404Instance = {
|
||||
};
|
||||
export {
|
||||
DEFAULT_404_ROUTE,
|
||||
DEFAULT_500_ROUTE,
|
||||
default404Instance,
|
||||
ensure404Route
|
||||
};
|
||||
|
5
node_modules/astro/dist/core/routing/default.d.ts
generated
vendored
5
node_modules/astro/dist/core/routing/default.d.ts
generated
vendored
@@ -1,10 +1,11 @@
|
||||
import type { ComponentInstance, ManifestData, SSRManifest } from '../../@types/astro.js';
|
||||
export declare function injectDefaultRoutes(ssrManifest: SSRManifest, routeManifest: ManifestData): ManifestData;
|
||||
import type { ComponentInstance } from '../../types/astro.js';
|
||||
import type { SSRManifest } from '../app/types.js';
|
||||
type DefaultRouteParams = {
|
||||
instance: ComponentInstance;
|
||||
matchesComponent(filePath: URL): boolean;
|
||||
route: string;
|
||||
component: string;
|
||||
};
|
||||
export declare const DEFAULT_COMPONENTS: string[];
|
||||
export declare function createDefaultRoutes(manifest: SSRManifest): DefaultRouteParams[];
|
||||
export {};
|
||||
|
21
node_modules/astro/dist/core/routing/default.js
generated
vendored
21
node_modules/astro/dist/core/routing/default.js
generated
vendored
@@ -1,20 +1,11 @@
|
||||
import { DEFAULT_404_COMPONENT } from "../constants.js";
|
||||
import {
|
||||
SERVER_ISLAND_COMPONENT,
|
||||
SERVER_ISLAND_ROUTE,
|
||||
createEndpoint as createServerIslandEndpoint,
|
||||
ensureServerIslandRoute
|
||||
SERVER_ISLAND_COMPONENT,
|
||||
SERVER_ISLAND_ROUTE
|
||||
} from "../server-islands/endpoint.js";
|
||||
import {
|
||||
DEFAULT_404_ROUTE,
|
||||
default404Instance,
|
||||
ensure404Route
|
||||
} from "./astro-designed-error-pages.js";
|
||||
function injectDefaultRoutes(ssrManifest, routeManifest) {
|
||||
ensure404Route(routeManifest);
|
||||
ensureServerIslandRoute(ssrManifest, routeManifest);
|
||||
return routeManifest;
|
||||
}
|
||||
import { DEFAULT_404_ROUTE, default404Instance } from "./astro-designed-error-pages.js";
|
||||
const DEFAULT_COMPONENTS = [DEFAULT_404_COMPONENT, SERVER_ISLAND_COMPONENT];
|
||||
function createDefaultRoutes(manifest) {
|
||||
const root = new URL(manifest.hrefRoot);
|
||||
return [
|
||||
@@ -33,6 +24,6 @@ function createDefaultRoutes(manifest) {
|
||||
];
|
||||
}
|
||||
export {
|
||||
createDefaultRoutes,
|
||||
injectDefaultRoutes
|
||||
DEFAULT_COMPONENTS,
|
||||
createDefaultRoutes
|
||||
};
|
||||
|
7
node_modules/astro/dist/core/routing/index.d.ts
generated
vendored
7
node_modules/astro/dist/core/routing/index.d.ts
generated
vendored
@@ -1,4 +1,3 @@
|
||||
export { createRouteManifest } from './manifest/create.js';
|
||||
export { deserializeRouteData, serializeRouteData } from './manifest/serialization.js';
|
||||
export { matchAllRoutes, matchRoute } from './match.js';
|
||||
export { validateDynamicRouteModule, validateGetStaticPathsResult } from './validation.js';
|
||||
export { createRoutesList } from './manifest/create.js';
|
||||
export { serializeRouteData } from './manifest/serialization.js';
|
||||
export { matchAllRoutes } from './match.js';
|
||||
|
15
node_modules/astro/dist/core/routing/index.js
generated
vendored
15
node_modules/astro/dist/core/routing/index.js
generated
vendored
@@ -1,13 +1,8 @@
|
||||
import { createRouteManifest } from "./manifest/create.js";
|
||||
import { deserializeRouteData, serializeRouteData } from "./manifest/serialization.js";
|
||||
import { matchAllRoutes, matchRoute } from "./match.js";
|
||||
import { validateDynamicRouteModule, validateGetStaticPathsResult } from "./validation.js";
|
||||
import { createRoutesList } from "./manifest/create.js";
|
||||
import { serializeRouteData } from "./manifest/serialization.js";
|
||||
import { matchAllRoutes } from "./match.js";
|
||||
export {
|
||||
createRouteManifest,
|
||||
deserializeRouteData,
|
||||
createRoutesList,
|
||||
matchAllRoutes,
|
||||
matchRoute,
|
||||
serializeRouteData,
|
||||
validateDynamicRouteModule,
|
||||
validateGetStaticPathsResult
|
||||
serializeRouteData
|
||||
};
|
||||
|
17
node_modules/astro/dist/core/routing/manifest/create.d.ts
generated
vendored
17
node_modules/astro/dist/core/routing/manifest/create.d.ts
generated
vendored
@@ -1,9 +1,7 @@
|
||||
import type { AstroSettings, ManifestData, RoutePart } from '../../../@types/astro.js';
|
||||
import type { Logger } from '../../logger/core.js';
|
||||
import nodeFs from 'node:fs';
|
||||
export declare function getParts(part: string, file: string): RoutePart[];
|
||||
export declare function validateSegment(segment: string, file?: string): void;
|
||||
export interface CreateRouteManifestParams {
|
||||
import type { AstroSettings, RoutesList } from '../../../types/astro.js';
|
||||
import type { Logger } from '../../logger/core.js';
|
||||
interface CreateRouteManifestParams {
|
||||
/** Astro Settings object */
|
||||
settings: AstroSettings;
|
||||
/** Current working directory */
|
||||
@@ -12,4 +10,11 @@ export interface CreateRouteManifestParams {
|
||||
fsMod?: typeof nodeFs;
|
||||
}
|
||||
/** Create manifest of all static routes */
|
||||
export declare function createRouteManifest(params: CreateRouteManifestParams, logger: Logger): ManifestData;
|
||||
export declare function createRoutesList(params: CreateRouteManifestParams, logger: Logger, { dev }?: {
|
||||
dev?: boolean;
|
||||
}): Promise<RoutesList>;
|
||||
export declare function resolveInjectedRoute(entrypoint: string, root: URL, cwd?: string): {
|
||||
resolved: string;
|
||||
component: string;
|
||||
};
|
||||
export {};
|
||||
|
171
node_modules/astro/dist/core/routing/manifest/create.js
generated
vendored
171
node_modules/astro/dist/core/routing/manifest/create.js
generated
vendored
@@ -3,24 +3,27 @@ import { createRequire } from "node:module";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { bold } from "kleur/colors";
|
||||
import pLimit from "p-limit";
|
||||
import { injectImageEndpoint } from "../../../assets/endpoint/config.js";
|
||||
import { toRoutingStrategy } from "../../../i18n/utils.js";
|
||||
import { runHookRoutesResolved } from "../../../integrations/hooks.js";
|
||||
import { getPrerenderDefault } from "../../../prerender/utils.js";
|
||||
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "../../constants.js";
|
||||
import { MissingIndexForInternationalization } from "../../errors/errors-data.js";
|
||||
import {
|
||||
MissingIndexForInternationalization,
|
||||
UnsupportedExternalRedirect
|
||||
} from "../../errors/errors-data.js";
|
||||
import { AstroError } from "../../errors/index.js";
|
||||
import { removeLeadingForwardSlash, slash } from "../../path.js";
|
||||
import { hasFileExtension, removeLeadingForwardSlash, slash } from "../../path.js";
|
||||
import { injectServerIslandRoute } from "../../server-islands/endpoint.js";
|
||||
import { resolvePages } from "../../util.js";
|
||||
import { ensure404Route } from "../astro-designed-error-pages.js";
|
||||
import { routeComparator } from "../priority.js";
|
||||
import { getRouteGenerator } from "./generator.js";
|
||||
import { getPattern } from "./pattern.js";
|
||||
import { getRoutePrerenderOption } from "./prerender.js";
|
||||
import { validateSegment } from "./segment.js";
|
||||
const require2 = createRequire(import.meta.url);
|
||||
function countOccurrences(needle, haystack) {
|
||||
let count = 0;
|
||||
for (const hay of haystack) {
|
||||
if (hay === needle) count += 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
const ROUTE_DYNAMIC_SPLIT = /\[(.+?\(.+?\)|.+?)\]/;
|
||||
const ROUTE_SPREAD = /^\.{3}.+$/;
|
||||
function getParts(part, file) {
|
||||
@@ -40,18 +43,6 @@ function getParts(part, file) {
|
||||
});
|
||||
return result;
|
||||
}
|
||||
function validateSegment(segment, file = "") {
|
||||
if (!file) file = segment;
|
||||
if (segment.includes("][")) {
|
||||
throw new Error(`Invalid route ${file} \u2014 parameters must be separated`);
|
||||
}
|
||||
if (countOccurrences("[", segment) !== countOccurrences("]", segment)) {
|
||||
throw new Error(`Invalid route ${file} \u2014 brackets are unbalanced`);
|
||||
}
|
||||
if ((/.+\[\.\.\.[^\]]+\]/.test(segment) || /\[\.\.\.[^\]]+\].+/.test(segment)) && file.endsWith(".astro")) {
|
||||
throw new Error(`Invalid route ${file} \u2014 rest parameter must be a standalone segment`);
|
||||
}
|
||||
}
|
||||
function isSemanticallyEqualSegment(segmentA, segmentB) {
|
||||
if (segmentA.length !== segmentB.length) {
|
||||
return false;
|
||||
@@ -105,7 +96,7 @@ function createFileBasedRoutes({ settings, cwd, fsMod }, logger) {
|
||||
const segment = isDir ? basename : name;
|
||||
validateSegment(segment, file);
|
||||
const parts = getParts(segment, file);
|
||||
const isIndex = isDir ? false : basename.startsWith("index.");
|
||||
const isIndex = isDir ? false : basename.substring(0, basename.lastIndexOf(".")) === "index";
|
||||
const routeSuffix = basename.slice(basename.indexOf("."), -ext.length);
|
||||
const isPage = validPageExtensions.has(ext);
|
||||
items.push({
|
||||
@@ -154,10 +145,10 @@ function createFileBasedRoutes({ settings, cwd, fsMod }, logger) {
|
||||
} else {
|
||||
components.push(item.file);
|
||||
const component = item.file;
|
||||
const { trailingSlash } = settings.config;
|
||||
const pathname = segments.every((segment) => segment.length === 1 && !segment[0].dynamic) ? `/${segments.map((segment) => segment[0].content).join("/")}` : null;
|
||||
const trailingSlash = trailingSlashForPath(pathname, settings.config);
|
||||
const pattern = getPattern(segments, settings.config.base, trailingSlash);
|
||||
const generate = getRouteGenerator(segments, trailingSlash);
|
||||
const pathname = segments.every((segment) => segment.length === 1 && !segment[0].dynamic) ? `/${segments.map((segment) => segment[0].content).join("/")}` : null;
|
||||
const route = joinSegments(segments);
|
||||
routes.push({
|
||||
route,
|
||||
@@ -170,7 +161,9 @@ function createFileBasedRoutes({ settings, cwd, fsMod }, logger) {
|
||||
generate,
|
||||
pathname: pathname || void 0,
|
||||
prerender,
|
||||
fallbackRoutes: []
|
||||
fallbackRoutes: [],
|
||||
distURL: [],
|
||||
origin: "project"
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -185,36 +178,26 @@ function createFileBasedRoutes({ settings, cwd, fsMod }, logger) {
|
||||
}
|
||||
return routes;
|
||||
}
|
||||
const trailingSlashForPath = (pathname, config) => pathname && hasFileExtension(pathname) ? "ignore" : config.trailingSlash;
|
||||
function createInjectedRoutes({ settings, cwd }) {
|
||||
const { config } = settings;
|
||||
const prerender = getPrerenderDefault(config);
|
||||
const routes = {
|
||||
normal: [],
|
||||
legacy: []
|
||||
};
|
||||
const priority = computeRoutePriority(config);
|
||||
const routes = [];
|
||||
for (const injectedRoute of settings.injectedRoutes) {
|
||||
const { pattern: name, entrypoint, prerender: prerenderInjected } = injectedRoute;
|
||||
let resolved;
|
||||
try {
|
||||
resolved = require2.resolve(entrypoint, { paths: [cwd || fileURLToPath(config.root)] });
|
||||
} catch {
|
||||
resolved = fileURLToPath(new URL(entrypoint, config.root));
|
||||
}
|
||||
const component = slash(path.relative(cwd || fileURLToPath(config.root), resolved));
|
||||
const { pattern: name, entrypoint, prerender: prerenderInjected, origin } = injectedRoute;
|
||||
const { resolved, component } = resolveInjectedRoute(entrypoint.toString(), config.root, cwd);
|
||||
const segments = removeLeadingForwardSlash(name).split(path.posix.sep).filter(Boolean).map((s) => {
|
||||
validateSegment(s);
|
||||
return getParts(s, component);
|
||||
});
|
||||
const type = resolved.endsWith(".astro") ? "page" : "endpoint";
|
||||
const isPage = type === "page";
|
||||
const trailingSlash = isPage ? config.trailingSlash : "never";
|
||||
const pathname = segments.every((segment) => segment.length === 1 && !segment[0].dynamic) ? `/${segments.map((segment) => segment[0].content).join("/")}` : null;
|
||||
const trailingSlash = trailingSlashForPath(pathname, config);
|
||||
const pattern = getPattern(segments, settings.config.base, trailingSlash);
|
||||
const generate = getRouteGenerator(segments, trailingSlash);
|
||||
const pathname = segments.every((segment) => segment.length === 1 && !segment[0].dynamic) ? `/${segments.map((segment) => segment[0].content).join("/")}` : null;
|
||||
const params = segments.flat().filter((p) => p.dynamic).map((p) => p.content);
|
||||
const route = joinSegments(segments);
|
||||
routes[priority].push({
|
||||
routes.push({
|
||||
type,
|
||||
// For backwards compatibility, an injected route is never considered an index route.
|
||||
isIndex: false,
|
||||
@@ -226,19 +209,17 @@ function createInjectedRoutes({ settings, cwd }) {
|
||||
generate,
|
||||
pathname: pathname || void 0,
|
||||
prerender: prerenderInjected ?? prerender,
|
||||
fallbackRoutes: []
|
||||
fallbackRoutes: [],
|
||||
distURL: [],
|
||||
origin
|
||||
});
|
||||
}
|
||||
return routes;
|
||||
}
|
||||
function createRedirectRoutes({ settings }, routeMap, logger) {
|
||||
function createRedirectRoutes({ settings }, routeMap) {
|
||||
const { config } = settings;
|
||||
const trailingSlash = config.trailingSlash;
|
||||
const routes = {
|
||||
normal: [],
|
||||
legacy: []
|
||||
};
|
||||
const priority = computeRoutePriority(settings.config);
|
||||
const routes = [];
|
||||
for (const [from, to] of Object.entries(settings.config.redirects)) {
|
||||
const segments = removeLeadingForwardSlash(from).split(path.posix.sep).filter(Boolean).map((s) => {
|
||||
validateSegment(s);
|
||||
@@ -255,13 +236,13 @@ function createRedirectRoutes({ settings }, routeMap, logger) {
|
||||
} else {
|
||||
destination = to.destination;
|
||||
}
|
||||
if (/^https?:\/\//.test(destination)) {
|
||||
logger.warn(
|
||||
"redirects",
|
||||
`Redirecting to an external URL is not officially supported: ${from} -> ${destination}`
|
||||
);
|
||||
if (URL.canParse(destination) && !/^https?:\/\//.test(destination)) {
|
||||
throw new AstroError({
|
||||
...UnsupportedExternalRedirect,
|
||||
message: UnsupportedExternalRedirect.message(from, destination)
|
||||
});
|
||||
}
|
||||
routes[priority].push({
|
||||
routes.push({
|
||||
type: "redirect",
|
||||
// For backwards compatibility, a redirect is never considered an index route.
|
||||
isIndex: false,
|
||||
@@ -272,10 +253,12 @@ function createRedirectRoutes({ settings }, routeMap, logger) {
|
||||
component: from,
|
||||
generate,
|
||||
pathname: pathname || void 0,
|
||||
prerender: false,
|
||||
prerender: getPrerenderDefault(config),
|
||||
redirect: to,
|
||||
redirectRoute: routeMap.get(destination),
|
||||
fallbackRoutes: []
|
||||
fallbackRoutes: [],
|
||||
distURL: [],
|
||||
origin: "project"
|
||||
});
|
||||
}
|
||||
return routes;
|
||||
@@ -318,7 +301,7 @@ function detectRouteCollision(a, b, _config, logger) {
|
||||
);
|
||||
logger.warn("router", "A collision will result in an hard error in following versions of Astro.");
|
||||
}
|
||||
function createRouteManifest(params, logger) {
|
||||
async function createRoutesList(params, logger, { dev = false } = {}) {
|
||||
const { settings } = params;
|
||||
const { config } = settings;
|
||||
const routeMap = /* @__PURE__ */ new Map();
|
||||
@@ -327,24 +310,37 @@ function createRouteManifest(params, logger) {
|
||||
routeMap.set(route.route, route);
|
||||
}
|
||||
const injectedRoutes = createInjectedRoutes(params);
|
||||
for (const [, routes2] of Object.entries(injectedRoutes)) {
|
||||
for (const route of routes2) {
|
||||
routeMap.set(route.route, route);
|
||||
}
|
||||
for (const route of injectedRoutes) {
|
||||
routeMap.set(route.route, route);
|
||||
}
|
||||
const redirectRoutes = createRedirectRoutes(params, routeMap, logger);
|
||||
const redirectRoutes = createRedirectRoutes(params, routeMap);
|
||||
const filteredFiledBasedRoutes = fileBasedRoutes.filter((fileBasedRoute) => {
|
||||
const isRedirect = redirectRoutes.findIndex((rd) => rd.route === fileBasedRoute.route);
|
||||
return isRedirect < 0;
|
||||
});
|
||||
const routes = [
|
||||
...injectedRoutes["legacy"].sort(routeComparator),
|
||||
...[...fileBasedRoutes, ...injectedRoutes["normal"], ...redirectRoutes["normal"]].sort(
|
||||
routeComparator
|
||||
),
|
||||
...redirectRoutes["legacy"].sort(routeComparator)
|
||||
...[...filteredFiledBasedRoutes, ...injectedRoutes, ...redirectRoutes].sort(routeComparator)
|
||||
];
|
||||
if (config.experimental.globalRoutePriority) {
|
||||
for (const [index, higherRoute] of routes.entries()) {
|
||||
for (const lowerRoute of routes.slice(index + 1)) {
|
||||
detectRouteCollision(higherRoute, lowerRoute, config, logger);
|
||||
}
|
||||
settings.buildOutput = getPrerenderDefault(config) ? "static" : "server";
|
||||
const limit = pLimit(10);
|
||||
let promises = [];
|
||||
for (const route of routes) {
|
||||
promises.push(
|
||||
limit(async () => {
|
||||
if (route.type !== "page" && route.type !== "endpoint") return;
|
||||
const localFs = params.fsMod ?? nodeFs;
|
||||
const content = await localFs.promises.readFile(
|
||||
fileURLToPath(new URL(route.component, settings.config.root)),
|
||||
"utf-8"
|
||||
);
|
||||
await getRoutePrerenderOption(content, route, settings, logger);
|
||||
})
|
||||
);
|
||||
}
|
||||
await Promise.all(promises);
|
||||
for (const [index, higherRoute] of routes.entries()) {
|
||||
for (const lowerRoute of routes.slice(index + 1)) {
|
||||
detectRouteCollision(higherRoute, lowerRoute, config, logger);
|
||||
}
|
||||
}
|
||||
const i18n = settings.config.i18n;
|
||||
@@ -485,15 +481,31 @@ function createRouteManifest(params, logger) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dev) {
|
||||
ensure404Route({ routes });
|
||||
}
|
||||
if (dev || settings.buildOutput === "server") {
|
||||
injectImageEndpoint(settings, { routes }, dev ? "dev" : "build");
|
||||
}
|
||||
if (dev || settings.config.adapter) {
|
||||
injectServerIslandRoute(settings.config, { routes });
|
||||
}
|
||||
await runHookRoutesResolved({ routes, settings, logger });
|
||||
return {
|
||||
routes
|
||||
};
|
||||
}
|
||||
function computeRoutePriority(config) {
|
||||
if (config.experimental.globalRoutePriority) {
|
||||
return "normal";
|
||||
function resolveInjectedRoute(entrypoint, root, cwd) {
|
||||
let resolved;
|
||||
try {
|
||||
resolved = require2.resolve(entrypoint, { paths: [cwd || fileURLToPath(root)] });
|
||||
} catch {
|
||||
resolved = fileURLToPath(new URL(entrypoint, root));
|
||||
}
|
||||
return "legacy";
|
||||
return {
|
||||
resolved,
|
||||
component: slash(path.relative(cwd || fileURLToPath(root), resolved))
|
||||
};
|
||||
}
|
||||
function joinSegments(segments) {
|
||||
const arr = segments.map((segment) => {
|
||||
@@ -502,7 +514,6 @@ function joinSegments(segments) {
|
||||
return `/${arr.join("/")}`.toLowerCase();
|
||||
}
|
||||
export {
|
||||
createRouteManifest,
|
||||
getParts,
|
||||
validateSegment
|
||||
createRoutesList,
|
||||
resolveInjectedRoute
|
||||
};
|
||||
|
3
node_modules/astro/dist/core/routing/manifest/generator.d.ts
generated
vendored
3
node_modules/astro/dist/core/routing/manifest/generator.d.ts
generated
vendored
@@ -1,2 +1,3 @@
|
||||
import type { AstroConfig, RoutePart } from '../../../@types/astro.js';
|
||||
import type { AstroConfig } from '../../../types/public/config.js';
|
||||
import type { RoutePart } from '../../../types/public/internal.js';
|
||||
export declare function getRouteGenerator(segments: RoutePart[][], addTrailingSlash: AstroConfig['trailingSlash']): (params: Record<string, string | number>) => string;
|
||||
|
2
node_modules/astro/dist/core/routing/manifest/parts.d.ts
generated
vendored
Normal file
2
node_modules/astro/dist/core/routing/manifest/parts.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { RoutePart } from '../../../types/public/index.js';
|
||||
export declare function getParts(part: string, file: string): RoutePart[];
|
22
node_modules/astro/dist/core/routing/manifest/parts.js
generated
vendored
Normal file
22
node_modules/astro/dist/core/routing/manifest/parts.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
const ROUTE_DYNAMIC_SPLIT = /\[(.+?\(.+?\)|.+?)\]/;
|
||||
const ROUTE_SPREAD = /^\.{3}.+$/;
|
||||
function getParts(part, file) {
|
||||
const result = [];
|
||||
part.split(ROUTE_DYNAMIC_SPLIT).map((str, i) => {
|
||||
if (!str) return;
|
||||
const dynamic = i % 2 === 1;
|
||||
const [, content] = dynamic ? /([^(]+)$/.exec(str) || [null, null] : [null, str];
|
||||
if (!content || dynamic && !/^(?:\.\.\.)?[\w$]+$/.test(content)) {
|
||||
throw new Error(`Invalid route ${file} \u2014 parameter name must match /^[a-zA-Z0-9_$]+$/`);
|
||||
}
|
||||
result.push({
|
||||
content,
|
||||
dynamic,
|
||||
spread: dynamic && ROUTE_SPREAD.test(content)
|
||||
});
|
||||
});
|
||||
return result;
|
||||
}
|
||||
export {
|
||||
getParts
|
||||
};
|
3
node_modules/astro/dist/core/routing/manifest/pattern.d.ts
generated
vendored
3
node_modules/astro/dist/core/routing/manifest/pattern.d.ts
generated
vendored
@@ -1,2 +1,3 @@
|
||||
import type { AstroConfig, RoutePart } from '../../../@types/astro.js';
|
||||
import type { AstroConfig } from '../../../types/public/config.js';
|
||||
import type { RoutePart } from '../../../types/public/internal.js';
|
||||
export declare function getPattern(segments: RoutePart[][], base: AstroConfig['base'], addTrailingSlash: AstroConfig['trailingSlash']): RegExp;
|
||||
|
4
node_modules/astro/dist/core/routing/manifest/prerender.d.ts
generated
vendored
Normal file
4
node_modules/astro/dist/core/routing/manifest/prerender.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { AstroSettings } from '../../../types/astro.js';
|
||||
import type { RouteData } from '../../../types/public/internal.js';
|
||||
import type { Logger } from '../../logger/core.js';
|
||||
export declare function getRoutePrerenderOption(content: string, route: RouteData, settings: AstroSettings, logger: Logger): Promise<void>;
|
17
node_modules/astro/dist/core/routing/manifest/prerender.js
generated
vendored
Normal file
17
node_modules/astro/dist/core/routing/manifest/prerender.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import { runHookRouteSetup } from "../../../integrations/hooks.js";
|
||||
import { getPrerenderDefault } from "../../../prerender/utils.js";
|
||||
const PRERENDER_REGEX = /^\s*export\s+const\s+prerender\s*=\s*(true|false);?/m;
|
||||
async function getRoutePrerenderOption(content, route, settings, logger) {
|
||||
const match = PRERENDER_REGEX.exec(content);
|
||||
if (match) {
|
||||
route.prerender = match[1] === "true";
|
||||
}
|
||||
await runHookRouteSetup({ route, settings, logger });
|
||||
if (typeof route.prerender === void 0) {
|
||||
route.prerender = getPrerenderDefault(settings.config);
|
||||
}
|
||||
if (!route.prerender) settings.buildOutput = "server";
|
||||
}
|
||||
export {
|
||||
getRoutePrerenderOption
|
||||
};
|
1
node_modules/astro/dist/core/routing/manifest/segment.d.ts
generated
vendored
Normal file
1
node_modules/astro/dist/core/routing/manifest/segment.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare function validateSegment(segment: string, file?: string): void;
|
22
node_modules/astro/dist/core/routing/manifest/segment.js
generated
vendored
Normal file
22
node_modules/astro/dist/core/routing/manifest/segment.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
function validateSegment(segment, file = "") {
|
||||
if (!file) file = segment;
|
||||
if (segment.includes("][")) {
|
||||
throw new Error(`Invalid route ${file} \u2014 parameters must be separated`);
|
||||
}
|
||||
if (countOccurrences("[", segment) !== countOccurrences("]", segment)) {
|
||||
throw new Error(`Invalid route ${file} \u2014 brackets are unbalanced`);
|
||||
}
|
||||
if ((/.+\[\.\.\.[^\]]+\]/.test(segment) || /\[\.\.\.[^\]]+\].+/.test(segment)) && file.endsWith(".astro")) {
|
||||
throw new Error(`Invalid route ${file} \u2014 rest parameter must be a standalone segment`);
|
||||
}
|
||||
}
|
||||
function countOccurrences(needle, haystack) {
|
||||
let count = 0;
|
||||
for (const hay of haystack) {
|
||||
if (hay === needle) count += 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
export {
|
||||
validateSegment
|
||||
};
|
4
node_modules/astro/dist/core/routing/manifest/serialization.d.ts
generated
vendored
4
node_modules/astro/dist/core/routing/manifest/serialization.d.ts
generated
vendored
@@ -1,3 +1,5 @@
|
||||
import type { AstroConfig, RouteData, SerializedRouteData } from '../../../@types/astro.js';
|
||||
import type { SerializedRouteData } from '../../../types/astro.js';
|
||||
import type { AstroConfig } from '../../../types/public/config.js';
|
||||
import type { RouteData } from '../../../types/public/internal.js';
|
||||
export declare function serializeRouteData(routeData: RouteData, trailingSlash: AstroConfig['trailingSlash']): SerializedRouteData;
|
||||
export declare function deserializeRouteData(rawRouteData: SerializedRouteData): RouteData;
|
||||
|
3
node_modules/astro/dist/core/routing/manifest/serialization.js
generated
vendored
3
node_modules/astro/dist/core/routing/manifest/serialization.js
generated
vendored
@@ -27,7 +27,8 @@ function deserializeRouteData(rawRouteData) {
|
||||
fallbackRoutes: rawRouteData.fallbackRoutes.map((fallback) => {
|
||||
return deserializeRouteData(fallback);
|
||||
}),
|
||||
isIndex: rawRouteData.isIndex
|
||||
isIndex: rawRouteData.isIndex,
|
||||
origin: rawRouteData.origin
|
||||
};
|
||||
}
|
||||
export {
|
||||
|
39
node_modules/astro/dist/core/routing/match.d.ts
generated
vendored
39
node_modules/astro/dist/core/routing/match.d.ts
generated
vendored
@@ -1,8 +1,11 @@
|
||||
import type { ManifestData, RouteData } from '../../@types/astro.js';
|
||||
import type { RoutesList } from '../../types/astro.js';
|
||||
import type { RouteData } from '../../types/public/internal.js';
|
||||
/** Find matching route from pathname */
|
||||
export declare function matchRoute(pathname: string, manifest: ManifestData): RouteData | undefined;
|
||||
export declare function matchRoute(pathname: string, manifest: RoutesList): RouteData | undefined;
|
||||
/** Finds all matching routes from pathname */
|
||||
export declare function matchAllRoutes(pathname: string, manifest: ManifestData): RouteData[];
|
||||
export declare function matchAllRoutes(pathname: string, manifest: RoutesList): RouteData[];
|
||||
export declare function isRoute404(route: string): boolean;
|
||||
export declare function isRoute500(route: string): boolean;
|
||||
/**
|
||||
* Determines if the given route matches a 404 or 500 error page.
|
||||
*
|
||||
@@ -10,3 +13,33 @@ export declare function matchAllRoutes(pathname: string, manifest: ManifestData)
|
||||
* @returns {boolean} `true` if the route matches a 404 or 500 error page, otherwise `false`.
|
||||
*/
|
||||
export declare function isRoute404or500(route: RouteData): boolean;
|
||||
/**
|
||||
* Determines if a given route is associated with the server island component.
|
||||
*
|
||||
* @param {RouteData} route - The route data object to evaluate.
|
||||
* @return {boolean} Returns true if the route's component is the server island component, otherwise false.
|
||||
*/
|
||||
export declare function isRouteServerIsland(route: RouteData): boolean;
|
||||
/**
|
||||
* Determines whether the given `Request` is targeted to a "server island" based on its URL.
|
||||
*
|
||||
* @param {Request} request - The request object to be evaluated.
|
||||
* @param {string} [base=''] - The base path provided via configuration.
|
||||
* @return {boolean} - Returns `true` if the request is for a server island, otherwise `false`.
|
||||
*/
|
||||
export declare function isRequestServerIsland(request: Request, base?: string): boolean;
|
||||
/**
|
||||
* Checks if the given request corresponds to a 404 or 500 route based on the specified base path.
|
||||
*
|
||||
* @param {Request} request - The HTTP request object to be checked.
|
||||
* @param {string} [base=''] - The base path to trim from the request's URL before checking the route. Default is an empty string.
|
||||
* @return {boolean} Returns true if the request matches a 404 or 500 route; otherwise, returns false.
|
||||
*/
|
||||
export declare function requestIs404Or500(request: Request, base?: string): boolean;
|
||||
/**
|
||||
* Determines whether a given route is an external redirect.
|
||||
*
|
||||
* @param {RouteData} route - The route object to check.
|
||||
* @return {boolean} Returns true if the route is an external redirect, otherwise false.
|
||||
*/
|
||||
export declare function isRouteExternalRedirect(route: RouteData): boolean;
|
||||
|
41
node_modules/astro/dist/core/routing/match.js
generated
vendored
41
node_modules/astro/dist/core/routing/match.js
generated
vendored
@@ -1,17 +1,48 @@
|
||||
import { redirectIsExternal } from "../redirects/render.js";
|
||||
import { SERVER_ISLAND_BASE_PREFIX, SERVER_ISLAND_COMPONENT } from "../server-islands/endpoint.js";
|
||||
function matchRoute(pathname, manifest) {
|
||||
const decodedPathname = decodeURI(pathname);
|
||||
return manifest.routes.find((route) => {
|
||||
return route.pattern.test(decodedPathname) || route.fallbackRoutes.some((fallbackRoute) => fallbackRoute.pattern.test(decodedPathname));
|
||||
return route.pattern.test(pathname) || route.fallbackRoutes.some((fallbackRoute) => fallbackRoute.pattern.test(pathname));
|
||||
});
|
||||
}
|
||||
function matchAllRoutes(pathname, manifest) {
|
||||
return manifest.routes.filter((route) => route.pattern.test(decodeURI(pathname)));
|
||||
return manifest.routes.filter((route) => route.pattern.test(pathname));
|
||||
}
|
||||
const ROUTE404_RE = /^\/404\/?$/;
|
||||
const ROUTE500_RE = /^\/500\/?$/;
|
||||
function isRoute404(route) {
|
||||
return ROUTE404_RE.test(route);
|
||||
}
|
||||
function isRoute500(route) {
|
||||
return ROUTE500_RE.test(route);
|
||||
}
|
||||
function isRoute404or500(route) {
|
||||
return route.pattern.test("/404") || route.pattern.test("/500");
|
||||
return isRoute404(route.route) || isRoute500(route.route);
|
||||
}
|
||||
function isRouteServerIsland(route) {
|
||||
return route.component === SERVER_ISLAND_COMPONENT;
|
||||
}
|
||||
function isRequestServerIsland(request, base = "") {
|
||||
const url = new URL(request.url);
|
||||
const pathname = base === "/" ? url.pathname.slice(base.length) : url.pathname.slice(base.length + 1);
|
||||
return pathname.startsWith(SERVER_ISLAND_BASE_PREFIX);
|
||||
}
|
||||
function requestIs404Or500(request, base = "") {
|
||||
const url = new URL(request.url);
|
||||
const pathname = url.pathname.slice(base.length);
|
||||
return isRoute404(pathname) || isRoute500(pathname);
|
||||
}
|
||||
function isRouteExternalRedirect(route) {
|
||||
return !!(route.type === "redirect" && route.redirect && redirectIsExternal(route.redirect));
|
||||
}
|
||||
export {
|
||||
isRequestServerIsland,
|
||||
isRoute404,
|
||||
isRoute404or500,
|
||||
isRoute500,
|
||||
isRouteExternalRedirect,
|
||||
isRouteServerIsland,
|
||||
matchAllRoutes,
|
||||
matchRoute
|
||||
matchRoute,
|
||||
requestIs404Or500
|
||||
};
|
||||
|
3
node_modules/astro/dist/core/routing/params.d.ts
generated
vendored
3
node_modules/astro/dist/core/routing/params.d.ts
generated
vendored
@@ -1,4 +1,5 @@
|
||||
import type { GetStaticPathsItem, RouteData } from '../../@types/astro.js';
|
||||
import type { GetStaticPathsItem } from '../../types/public/common.js';
|
||||
import type { RouteData } from '../../types/public/internal.js';
|
||||
/**
|
||||
* given a route's Params object, validate parameter
|
||||
* values and create a stringified key for the route
|
||||
|
2
node_modules/astro/dist/core/routing/priority.d.ts
generated
vendored
2
node_modules/astro/dist/core/routing/priority.d.ts
generated
vendored
@@ -1,4 +1,4 @@
|
||||
import type { RouteData } from '../../@types/astro.js';
|
||||
import type { RouteData } from '../../types/public/internal.js';
|
||||
/**
|
||||
* Comparator for sorting routes in resolution order.
|
||||
*
|
||||
|
1
node_modules/astro/dist/core/routing/request.d.ts
generated
vendored
1
node_modules/astro/dist/core/routing/request.d.ts
generated
vendored
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* Utilities for extracting information from `Request`
|
||||
*/
|
||||
export declare function getFirstForwardedValue(multiValueHeader?: string | string[] | null): string | undefined;
|
||||
/**
|
||||
* Returns the first value associated to the `x-forwarded-for` header.
|
||||
*
|
||||
|
3
node_modules/astro/dist/core/routing/request.js
generated
vendored
3
node_modules/astro/dist/core/routing/request.js
generated
vendored
@@ -5,6 +5,5 @@ function getClientIpAddress(request) {
|
||||
return getFirstForwardedValue(request.headers.get("x-forwarded-for"));
|
||||
}
|
||||
export {
|
||||
getClientIpAddress,
|
||||
getFirstForwardedValue
|
||||
getClientIpAddress
|
||||
};
|
||||
|
22
node_modules/astro/dist/core/routing/rewrite.d.ts
generated
vendored
22
node_modules/astro/dist/core/routing/rewrite.d.ts
generated
vendored
@@ -1,13 +1,17 @@
|
||||
import type { AstroConfig, RewritePayload, RouteData } from '../../@types/astro.js';
|
||||
export type FindRouteToRewrite = {
|
||||
import type { RewritePayload } from '../../types/public/common.js';
|
||||
import type { AstroConfig } from '../../types/public/config.js';
|
||||
import type { RouteData } from '../../types/public/internal.js';
|
||||
import type { Logger } from '../logger/core.js';
|
||||
type FindRouteToRewrite = {
|
||||
payload: RewritePayload;
|
||||
routes: RouteData[];
|
||||
request: Request;
|
||||
trailingSlash: AstroConfig['trailingSlash'];
|
||||
buildFormat: AstroConfig['build']['format'];
|
||||
base: AstroConfig['base'];
|
||||
outDir: URL | string;
|
||||
};
|
||||
export interface FindRouteToRewriteResult {
|
||||
interface FindRouteToRewriteResult {
|
||||
routeData: RouteData;
|
||||
newUrl: URL;
|
||||
pathname: string;
|
||||
@@ -17,13 +21,17 @@ export interface FindRouteToRewriteResult {
|
||||
* 1. The new `Request` object. It contains `base`
|
||||
* 2.
|
||||
*/
|
||||
export declare function findRouteToRewrite({ payload, routes, request, trailingSlash, buildFormat, base, }: FindRouteToRewrite): FindRouteToRewriteResult;
|
||||
export declare function findRouteToRewrite({ payload, routes, request, trailingSlash, buildFormat, base, outDir, }: FindRouteToRewrite): FindRouteToRewriteResult;
|
||||
/**
|
||||
* Utility function that creates a new `Request` with a new URL from an old `Request`.
|
||||
*
|
||||
* @param newUrl The new `URL`
|
||||
* @param oldRequest The old `Request`
|
||||
* @param isPrerendered It needs to be the flag of the previous routeData, before the rewrite
|
||||
* @param logger
|
||||
* @param routePattern
|
||||
*/
|
||||
export declare function copyRequest(newUrl: URL, oldRequest: Request): Request;
|
||||
export declare function setOriginPathname(request: Request, pathname: string): void;
|
||||
export declare function getOriginPathname(request: Request): string | undefined;
|
||||
export declare function copyRequest(newUrl: URL, oldRequest: Request, isPrerendered: boolean, logger: Logger, routePattern: string): Request;
|
||||
export declare function setOriginPathname(request: Request, pathname: string, trailingSlash: AstroConfig['trailingSlash'], buildFormat: AstroConfig['build']['format']): void;
|
||||
export declare function getOriginPathname(request: Request): string;
|
||||
export {};
|
||||
|
104
node_modules/astro/dist/core/routing/rewrite.js
generated
vendored
104
node_modules/astro/dist/core/routing/rewrite.js
generated
vendored
@@ -1,7 +1,14 @@
|
||||
import { shouldAppendForwardSlash } from "../build/util.js";
|
||||
import { originPathnameSymbol } from "../constants.js";
|
||||
import { AstroError, AstroErrorData } from "../errors/index.js";
|
||||
import { appendForwardSlash, removeTrailingForwardSlash } from "../path.js";
|
||||
import {
|
||||
appendForwardSlash,
|
||||
joinPaths,
|
||||
prependForwardSlash,
|
||||
removeTrailingForwardSlash,
|
||||
trimSlashes
|
||||
} from "../path.js";
|
||||
import { createRequest } from "../request.js";
|
||||
import { DEFAULT_404_ROUTE } from "./astro-designed-error-pages.js";
|
||||
function findRouteToRewrite({
|
||||
payload,
|
||||
@@ -9,7 +16,8 @@ function findRouteToRewrite({
|
||||
request,
|
||||
trailingSlash,
|
||||
buildFormat,
|
||||
base
|
||||
base,
|
||||
outDir
|
||||
}) {
|
||||
let newUrl = void 0;
|
||||
if (payload instanceof URL) {
|
||||
@@ -20,13 +28,41 @@ function findRouteToRewrite({
|
||||
newUrl = new URL(payload, new URL(request.url).origin);
|
||||
}
|
||||
let pathname = newUrl.pathname;
|
||||
if (base !== "/" && newUrl.pathname.startsWith(base)) {
|
||||
pathname = shouldAppendForwardSlash(trailingSlash, buildFormat) ? appendForwardSlash(newUrl.pathname) : removeTrailingForwardSlash(newUrl.pathname);
|
||||
pathname = pathname.slice(base.length);
|
||||
const shouldAppendSlash = shouldAppendForwardSlash(trailingSlash, buildFormat);
|
||||
if (base !== "/") {
|
||||
const isBasePathRequest = newUrl.pathname === base || newUrl.pathname === removeTrailingForwardSlash(base);
|
||||
if (isBasePathRequest) {
|
||||
pathname = shouldAppendSlash ? "/" : "";
|
||||
} else if (newUrl.pathname.startsWith(base)) {
|
||||
pathname = shouldAppendSlash ? appendForwardSlash(newUrl.pathname) : removeTrailingForwardSlash(newUrl.pathname);
|
||||
pathname = pathname.slice(base.length);
|
||||
}
|
||||
}
|
||||
if (!pathname.startsWith("/") && shouldAppendSlash && newUrl.pathname.endsWith("/")) {
|
||||
pathname = prependForwardSlash(pathname);
|
||||
}
|
||||
if (pathname === "/" && base !== "/" && !shouldAppendSlash) {
|
||||
pathname = "";
|
||||
}
|
||||
if (buildFormat === "file") {
|
||||
pathname = pathname.replace(/\.html$/, "");
|
||||
}
|
||||
if (base !== "/" && (pathname === "" || pathname === "/") && !shouldAppendSlash) {
|
||||
newUrl.pathname = removeTrailingForwardSlash(base);
|
||||
} else {
|
||||
newUrl.pathname = joinPaths(...[base, pathname].filter(Boolean));
|
||||
}
|
||||
const decodedPathname = decodeURI(pathname);
|
||||
let foundRoute;
|
||||
for (const route of routes) {
|
||||
if (route.pattern.test(decodeURI(pathname))) {
|
||||
if (route.pattern.test(decodedPathname)) {
|
||||
if (route.params && route.params.length !== 0 && route.distURL && route.distURL.length !== 0) {
|
||||
if (!route.distURL.find(
|
||||
(url) => url.href.replace(outDir.toString(), "").replace(/(?:\/index\.html|\.html)$/, "") == trimSlashes(decodedPathname)
|
||||
)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
foundRoute = route;
|
||||
break;
|
||||
}
|
||||
@@ -35,7 +71,7 @@ function findRouteToRewrite({
|
||||
return {
|
||||
routeData: foundRoute,
|
||||
newUrl,
|
||||
pathname
|
||||
pathname: decodedPathname
|
||||
};
|
||||
} else {
|
||||
const custom404 = routes.find((route) => route.route === "/404");
|
||||
@@ -46,37 +82,55 @@ function findRouteToRewrite({
|
||||
}
|
||||
}
|
||||
}
|
||||
function copyRequest(newUrl, oldRequest) {
|
||||
function copyRequest(newUrl, oldRequest, isPrerendered, logger, routePattern) {
|
||||
if (oldRequest.bodyUsed) {
|
||||
throw new AstroError(AstroErrorData.RewriteWithBodyUsed);
|
||||
}
|
||||
return new Request(newUrl, {
|
||||
return createRequest({
|
||||
url: newUrl,
|
||||
method: oldRequest.method,
|
||||
headers: oldRequest.headers,
|
||||
body: oldRequest.body,
|
||||
referrer: oldRequest.referrer,
|
||||
referrerPolicy: oldRequest.referrerPolicy,
|
||||
mode: oldRequest.mode,
|
||||
credentials: oldRequest.credentials,
|
||||
cache: oldRequest.cache,
|
||||
redirect: oldRequest.redirect,
|
||||
integrity: oldRequest.integrity,
|
||||
signal: oldRequest.signal,
|
||||
keepalive: oldRequest.keepalive,
|
||||
// https://fetch.spec.whatwg.org/#dom-request-duplex
|
||||
// @ts-expect-error It isn't part of the types, but undici accepts it and it allows to carry over the body to a new request
|
||||
duplex: "half"
|
||||
isPrerendered,
|
||||
logger,
|
||||
headers: isPrerendered ? {} : oldRequest.headers,
|
||||
routePattern,
|
||||
init: {
|
||||
referrer: oldRequest.referrer,
|
||||
referrerPolicy: oldRequest.referrerPolicy,
|
||||
mode: oldRequest.mode,
|
||||
credentials: oldRequest.credentials,
|
||||
cache: oldRequest.cache,
|
||||
redirect: oldRequest.redirect,
|
||||
integrity: oldRequest.integrity,
|
||||
signal: oldRequest.signal,
|
||||
keepalive: oldRequest.keepalive,
|
||||
// https://fetch.spec.whatwg.org/#dom-request-duplex
|
||||
// @ts-expect-error It isn't part of the types, but undici accepts it and it allows to carry over the body to a new request
|
||||
duplex: "half"
|
||||
}
|
||||
});
|
||||
}
|
||||
function setOriginPathname(request, pathname) {
|
||||
Reflect.set(request, originPathnameSymbol, encodeURIComponent(pathname));
|
||||
function setOriginPathname(request, pathname, trailingSlash, buildFormat) {
|
||||
if (!pathname) {
|
||||
pathname = "/";
|
||||
}
|
||||
const shouldAppendSlash = shouldAppendForwardSlash(trailingSlash, buildFormat);
|
||||
let finalPathname;
|
||||
if (pathname === "/") {
|
||||
finalPathname = "/";
|
||||
} else if (shouldAppendSlash) {
|
||||
finalPathname = appendForwardSlash(pathname);
|
||||
} else {
|
||||
finalPathname = removeTrailingForwardSlash(pathname);
|
||||
}
|
||||
Reflect.set(request, originPathnameSymbol, encodeURIComponent(finalPathname));
|
||||
}
|
||||
function getOriginPathname(request) {
|
||||
const origin = Reflect.get(request, originPathnameSymbol);
|
||||
if (origin) {
|
||||
return decodeURIComponent(origin);
|
||||
}
|
||||
return void 0;
|
||||
return new URL(request.url).pathname;
|
||||
}
|
||||
export {
|
||||
copyRequest,
|
||||
|
4
node_modules/astro/dist/core/routing/validation.d.ts
generated
vendored
4
node_modules/astro/dist/core/routing/validation.d.ts
generated
vendored
@@ -1,4 +1,6 @@
|
||||
import type { ComponentInstance, GetStaticPathsResult, RouteData } from '../../@types/astro.js';
|
||||
import type { ComponentInstance } from '../../types/astro.js';
|
||||
import type { GetStaticPathsResult } from '../../types/public/common.js';
|
||||
import type { RouteData } from '../../types/public/internal.js';
|
||||
import type { Logger } from '../logger/core.js';
|
||||
/** Throws error for invalid parameter in getStaticPaths() response */
|
||||
export declare function validateGetStaticPathsParameter([key, value]: [string, any], route: string): void;
|
||||
|
Reference in New Issue
Block a user