astro 4.9.2 → 4.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +8 -0
- package/components/Picture.astro +2 -1
- package/config.d.ts +6 -0
- package/config.mjs +1 -0
- package/dist/@types/astro.d.ts +124 -0
- package/dist/assets/utils/proxy.js +1 -1
- package/dist/cli/add/babel.d.ts +1 -1
- package/dist/cli/install-package.d.ts +1 -1
- package/dist/cli/install-package.js +1 -1
- package/dist/config/index.js +2 -2
- package/dist/container/index.d.ts +11 -15
- package/dist/container/index.js +29 -27
- package/dist/container/pipeline.d.ts +1 -0
- package/dist/container/pipeline.js +8 -1
- package/dist/content/types-generator.js +5 -5
- package/dist/content/utils.d.ts +2 -3
- package/dist/content/utils.js +3 -4
- package/dist/content/vite-plugin-content-virtual-mod.d.ts +1 -1
- package/dist/core/app/pipeline.d.ts +2 -1
- package/dist/core/app/pipeline.js +44 -19
- package/dist/core/app/types.d.ts +1 -0
- package/dist/core/base-pipeline.d.ts +15 -3
- package/dist/core/base-pipeline.js +10 -1
- package/dist/core/build/generate.js +14 -4
- package/dist/core/build/pipeline.d.ts +2 -1
- package/dist/core/build/pipeline.js +31 -19
- package/dist/core/build/plugins/plugin-content.js +2 -1
- package/dist/core/build/plugins/plugin-manifest.js +2 -1
- package/dist/core/config/config.js +1 -1
- package/dist/core/config/schema.d.ts +644 -0
- package/dist/core/config/schema.js +5 -1
- package/dist/core/config/settings.js +1 -0
- package/dist/core/constants.d.ts +1 -1
- package/dist/core/constants.js +2 -2
- package/dist/core/create-vite.js +2 -0
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +61 -1
- package/dist/core/errors/errors-data.js +39 -0
- package/dist/core/logger/core.d.ts +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render-context.d.ts +1 -0
- package/dist/core/render-context.js +74 -57
- package/dist/core/routing/astro-designed-error-pages.d.ts +8 -1
- package/dist/core/routing/astro-designed-error-pages.js +29 -12
- package/dist/env/config.d.ts +9 -0
- package/dist/env/config.js +17 -0
- package/dist/env/constants.d.ts +11 -0
- package/dist/env/constants.js +21 -0
- package/dist/env/runtime.d.ts +6 -0
- package/dist/env/runtime.js +21 -0
- package/dist/env/schema.d.ts +387 -0
- package/dist/env/schema.js +113 -0
- package/dist/env/validators.d.ts +13 -0
- package/dist/env/validators.js +57 -0
- package/dist/env/vite-plugin-env.d.ts +11 -0
- package/dist/env/vite-plugin-env.js +174 -0
- package/dist/integrations/features-validation.js +9 -1
- package/dist/jsx/server.js +2 -1
- package/dist/runtime/server/render/astro/render.js +15 -1
- package/dist/runtime/server/util.js +1 -1
- package/dist/virtual-modules/container.d.ts +16 -0
- package/dist/virtual-modules/container.js +18 -0
- package/dist/virtual-modules/env-setup.d.ts +1 -0
- package/dist/virtual-modules/env-setup.js +4 -0
- package/dist/vite-plugin-astro-server/pipeline.d.ts +3 -2
- package/dist/vite-plugin-astro-server/pipeline.js +34 -20
- package/dist/vite-plugin-astro-server/plugin.js +1 -0
- package/dist/vite-plugin-astro-server/response.d.ts +0 -6
- package/dist/vite-plugin-astro-server/response.js +0 -13
- package/dist/vite-plugin-astro-server/route.js +2 -1
- package/dist/vite-plugin-inject-env-ts/index.js +46 -38
- package/package.json +19 -20
- package/templates/env/module.mjs +18 -0
- package/templates/env/types.d.ts +20 -0
- /package/{content-module.template.mjs → templates/content/module.mjs} +0 -0
- /package/{content-types.template.d.ts → templates/content/types.d.ts} +0 -0
|
@@ -3,6 +3,7 @@ import { bundledThemes } from "shiki";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
+
import { EnvSchema } from "../../env/schema.js";
|
|
6
7
|
import { appendForwardSlash, prependForwardSlash, removeTrailingForwardSlash } from "../path.js";
|
|
7
8
|
const ASTRO_CONFIG_DEFAULTS = {
|
|
8
9
|
root: ".",
|
|
@@ -325,7 +326,10 @@ const AstroConfigSchema = z.object({
|
|
|
325
326
|
contentCollectionJsonSchema: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.contentCollectionJsonSchema),
|
|
326
327
|
clientPrerender: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.clientPrerender),
|
|
327
328
|
globalRoutePriority: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.globalRoutePriority),
|
|
328
|
-
rewriting: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.rewriting)
|
|
329
|
+
rewriting: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.rewriting),
|
|
330
|
+
env: z.object({
|
|
331
|
+
schema: EnvSchema.optional()
|
|
332
|
+
}).strict().optional()
|
|
329
333
|
}).strict(
|
|
330
334
|
`Invalid or outdated experimental feature.
|
|
331
335
|
Check for incorrect spelling or outdated Astro version.
|
package/dist/core/constants.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export declare const ROUTE_TYPE_HEADER = "X-Astro-Route-Type";
|
|
|
26
26
|
/**
|
|
27
27
|
* The value of the `component` field of the default 404 page, which is used when there is no user-provided 404.astro page.
|
|
28
28
|
*/
|
|
29
|
-
export declare const DEFAULT_404_COMPONENT = "astro-default-404";
|
|
29
|
+
export declare const DEFAULT_404_COMPONENT = "astro-default-404.astro";
|
|
30
30
|
/**
|
|
31
31
|
* A response with one of these status codes will be rewritten
|
|
32
32
|
* with the result of rendering the respective error page.
|
package/dist/core/constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const ASTRO_VERSION = "4.
|
|
1
|
+
const ASTRO_VERSION = "4.10.0";
|
|
2
2
|
const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
|
|
3
3
|
const ROUTE_TYPE_HEADER = "X-Astro-Route-Type";
|
|
4
|
-
const DEFAULT_404_COMPONENT = "astro-default-404";
|
|
4
|
+
const DEFAULT_404_COMPONENT = "astro-default-404.astro";
|
|
5
5
|
const REROUTABLE_STATUS_CODES = [404, 500];
|
|
6
6
|
const clientAddressSymbol = Symbol.for("astro.clientAddress");
|
|
7
7
|
const clientLocalsSymbol = Symbol.for("astro.locals");
|
package/dist/core/create-vite.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
astroContentImportPlugin,
|
|
11
11
|
astroContentVirtualModPlugin
|
|
12
12
|
} from "../content/index.js";
|
|
13
|
+
import { astroEnv } from "../env/vite-plugin-env.js";
|
|
13
14
|
import astroInternationalization from "../i18n/vite-plugin-i18n.js";
|
|
14
15
|
import astroPrefetch from "../prefetch/vite-plugin-prefetch.js";
|
|
15
16
|
import astroDevToolbar from "../toolbar/vite-plugin-dev-toolbar.js";
|
|
@@ -110,6 +111,7 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
|
|
|
110
111
|
// the build to run very slow as the filewatcher is triggered often.
|
|
111
112
|
mode !== "build" && vitePluginAstroServer({ settings, logger, fs }),
|
|
112
113
|
envVitePlugin({ settings }),
|
|
114
|
+
astroEnv({ settings, mode, fs }),
|
|
113
115
|
markdownVitePlugin({ settings, logger }),
|
|
114
116
|
htmlVitePlugin(),
|
|
115
117
|
mdxVitePlugin(),
|
package/dist/core/dev/dev.js
CHANGED
|
@@ -19,7 +19,7 @@ async function dev(inlineConfig) {
|
|
|
19
19
|
await telemetry.record([]);
|
|
20
20
|
const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
|
|
21
21
|
const logger = restart.container.logger;
|
|
22
|
-
const currentVersion = "4.
|
|
22
|
+
const currentVersion = "4.10.0";
|
|
23
23
|
const isPrerelease = currentVersion.includes("-");
|
|
24
24
|
if (!isPrerelease) {
|
|
25
25
|
try {
|
|
@@ -1000,6 +1000,27 @@ export declare const MissingMiddlewareForInternationalization: {
|
|
|
1000
1000
|
title: string;
|
|
1001
1001
|
message: string;
|
|
1002
1002
|
};
|
|
1003
|
+
/**
|
|
1004
|
+
* @docs
|
|
1005
|
+
* @description
|
|
1006
|
+
* The user tried to rewrite using a route that doesn't exist, or it emitted a runtime error during its rendering phase.
|
|
1007
|
+
*/
|
|
1008
|
+
export declare const RewriteEncounteredAnError: {
|
|
1009
|
+
name: string;
|
|
1010
|
+
title: string;
|
|
1011
|
+
message: (route: string, stack?: string) => string;
|
|
1012
|
+
};
|
|
1013
|
+
/**
|
|
1014
|
+
* @docs
|
|
1015
|
+
* @description
|
|
1016
|
+
*
|
|
1017
|
+
* The user tried to rewrite a 404 page inside a static page.
|
|
1018
|
+
*/
|
|
1019
|
+
export declare const InvalidRewrite404: {
|
|
1020
|
+
name: string;
|
|
1021
|
+
title: string;
|
|
1022
|
+
message: string;
|
|
1023
|
+
};
|
|
1003
1024
|
/**
|
|
1004
1025
|
* @docs
|
|
1005
1026
|
* @description
|
|
@@ -1050,7 +1071,6 @@ export declare const i18nNotEnabled: {
|
|
|
1050
1071
|
/**
|
|
1051
1072
|
* @docs
|
|
1052
1073
|
* @description
|
|
1053
|
-
*
|
|
1054
1074
|
* Astro couldn't find a route matching the one provided by the user
|
|
1055
1075
|
*/
|
|
1056
1076
|
export declare const RouteNotFound: {
|
|
@@ -1058,6 +1078,46 @@ export declare const RouteNotFound: {
|
|
|
1058
1078
|
title: string;
|
|
1059
1079
|
message: string;
|
|
1060
1080
|
};
|
|
1081
|
+
/**
|
|
1082
|
+
* @docs
|
|
1083
|
+
* @description
|
|
1084
|
+
* Some environment variables do not match the data type and/or properties defined in `experimental.env.schema`.
|
|
1085
|
+
*/
|
|
1086
|
+
export declare const EnvInvalidVariables: {
|
|
1087
|
+
name: string;
|
|
1088
|
+
title: string;
|
|
1089
|
+
message: (variables: string) => string;
|
|
1090
|
+
};
|
|
1091
|
+
/**
|
|
1092
|
+
* @docs
|
|
1093
|
+
* @description
|
|
1094
|
+
* An environment variable does not match the data type and/or properties defined in `experimental.env.schema`.
|
|
1095
|
+
*/
|
|
1096
|
+
export declare const EnvInvalidVariable: {
|
|
1097
|
+
name: string;
|
|
1098
|
+
title: string;
|
|
1099
|
+
message: (key: string, type: string) => string;
|
|
1100
|
+
};
|
|
1101
|
+
/**
|
|
1102
|
+
* @docs
|
|
1103
|
+
* @description
|
|
1104
|
+
* The `astro:env/server` exported function `getSecret()` is not supported by your adapter.
|
|
1105
|
+
*/
|
|
1106
|
+
export declare const EnvUnsupportedGetSecret: {
|
|
1107
|
+
name: string;
|
|
1108
|
+
title: string;
|
|
1109
|
+
message: string;
|
|
1110
|
+
};
|
|
1111
|
+
/**
|
|
1112
|
+
* @docs
|
|
1113
|
+
* @description
|
|
1114
|
+
* This module is only available server-side.
|
|
1115
|
+
*/
|
|
1116
|
+
export declare const ServerOnlyModule: {
|
|
1117
|
+
name: string;
|
|
1118
|
+
title: string;
|
|
1119
|
+
message: (name: string) => string;
|
|
1120
|
+
};
|
|
1061
1121
|
/**
|
|
1062
1122
|
* @docs
|
|
1063
1123
|
* @kind heading
|
|
@@ -356,6 +356,16 @@ const MissingMiddlewareForInternationalization = {
|
|
|
356
356
|
title: "Enabled manual internationalization routing without having a middleware.",
|
|
357
357
|
message: "Your configuration setting `i18n.routing: 'manual'` requires you to provide your own i18n `middleware` file."
|
|
358
358
|
};
|
|
359
|
+
const RewriteEncounteredAnError = {
|
|
360
|
+
name: "RewriteEncounteredAnError",
|
|
361
|
+
title: "Astro couldn't find the route to rewrite, or if was found but it emitted an error during the rendering phase.",
|
|
362
|
+
message: (route, stack) => `The route ${route} that you tried to render doesn't exist, or it emitted an error during the rendering phase. ${stack ? stack : ""}.`
|
|
363
|
+
};
|
|
364
|
+
const InvalidRewrite404 = {
|
|
365
|
+
name: "InvalidRewrite404",
|
|
366
|
+
title: "You attempted to rewrite a 404 inside a static page, and this isn't allowed.",
|
|
367
|
+
message: "Rewriting a 404 is only allowed inside on-demand pages."
|
|
368
|
+
};
|
|
359
369
|
const CantRenderPage = {
|
|
360
370
|
name: "CantRenderPage",
|
|
361
371
|
title: "Astro can't render the route.",
|
|
@@ -380,6 +390,29 @@ const RouteNotFound = {
|
|
|
380
390
|
title: "Route not found.",
|
|
381
391
|
message: `Astro could not find a route that matches the one you requested.`
|
|
382
392
|
};
|
|
393
|
+
const EnvInvalidVariables = {
|
|
394
|
+
name: "EnvInvalidVariables",
|
|
395
|
+
title: "Invalid Environment Variables",
|
|
396
|
+
message: (variables) => `The following environment variables do not match the data type and/or properties defined in \`experimental.env.schema\`:
|
|
397
|
+
|
|
398
|
+
${variables}
|
|
399
|
+
`
|
|
400
|
+
};
|
|
401
|
+
const EnvInvalidVariable = {
|
|
402
|
+
name: "EnvInvalidVariable",
|
|
403
|
+
title: "Invalid Environment Variable",
|
|
404
|
+
message: (key, type) => `The following environment variable does not match the data type and/or properties defined in \`experimental.env.schema\`: ${key} is not of type ${type}`
|
|
405
|
+
};
|
|
406
|
+
const EnvUnsupportedGetSecret = {
|
|
407
|
+
name: "EnvUnsupportedGetSecret",
|
|
408
|
+
title: "Unsupported astro:env getSecret",
|
|
409
|
+
message: "`astro:env/server` exported function `getSecret` is not supported by your adapter."
|
|
410
|
+
};
|
|
411
|
+
const ServerOnlyModule = {
|
|
412
|
+
name: "ServerOnlyModule",
|
|
413
|
+
title: "Module is only available server-side",
|
|
414
|
+
message: (name) => `The "${name}" module is only available server-side.`
|
|
415
|
+
};
|
|
383
416
|
const UnknownCSSError = {
|
|
384
417
|
name: "UnknownCSSError",
|
|
385
418
|
title: "Unknown CSS Error."
|
|
@@ -533,6 +566,9 @@ export {
|
|
|
533
566
|
DataCollectionEntryParseError,
|
|
534
567
|
DuplicateContentEntrySlugError,
|
|
535
568
|
EndpointDidNotReturnAResponse,
|
|
569
|
+
EnvInvalidVariable,
|
|
570
|
+
EnvInvalidVariables,
|
|
571
|
+
EnvUnsupportedGetSecret,
|
|
536
572
|
ExpectedImage,
|
|
537
573
|
ExpectedImageOptions,
|
|
538
574
|
FailedToFetchRemoteImageDimensions,
|
|
@@ -558,6 +594,7 @@ export {
|
|
|
558
594
|
InvalidGlob,
|
|
559
595
|
InvalidImageService,
|
|
560
596
|
InvalidPrerenderExport,
|
|
597
|
+
InvalidRewrite404,
|
|
561
598
|
LocalImageUsedWrongly,
|
|
562
599
|
LocalsNotAnObject,
|
|
563
600
|
MarkdownFrontmatterParseError,
|
|
@@ -588,7 +625,9 @@ export {
|
|
|
588
625
|
RedirectWithNoLocation,
|
|
589
626
|
ReservedSlotName,
|
|
590
627
|
ResponseSentError,
|
|
628
|
+
RewriteEncounteredAnError,
|
|
591
629
|
RouteNotFound,
|
|
630
|
+
ServerOnlyModule,
|
|
592
631
|
StaticClientAddressNotAvailable,
|
|
593
632
|
StaticRedirectNotAvailable,
|
|
594
633
|
UnhandledRejection,
|
|
@@ -7,7 +7,7 @@ export type LoggerLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
|
7
7
|
* rather than specific to a single command, function, use, etc. The label will be
|
|
8
8
|
* shown in the log message to the user, so it should be relevant.
|
|
9
9
|
*/
|
|
10
|
-
export type LoggerLabel = 'add' | 'build' | 'check' | 'config' | 'content' | 'deprecated' | 'markdown' | 'router' | 'types' | 'vite' | 'watch' | 'middleware' | 'preferences' | 'redirects' | 'toolbar' | 'assets' | 'update' | 'SKIP_FORMAT';
|
|
10
|
+
export type LoggerLabel = 'add' | 'build' | 'check' | 'config' | 'content' | 'deprecated' | 'markdown' | 'router' | 'types' | 'vite' | 'watch' | 'middleware' | 'preferences' | 'redirects' | 'toolbar' | 'assets' | 'env' | 'update' | 'SKIP_FORMAT';
|
|
11
11
|
export interface LogOptions {
|
|
12
12
|
dest: LogWritable<LogMessage>;
|
|
13
13
|
level: LoggerLevel;
|
package/dist/core/messages.js
CHANGED
|
@@ -37,7 +37,7 @@ function serverStart({
|
|
|
37
37
|
host,
|
|
38
38
|
base
|
|
39
39
|
}) {
|
|
40
|
-
const version = "4.
|
|
40
|
+
const version = "4.10.0";
|
|
41
41
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
42
42
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
43
43
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -269,7 +269,7 @@ function printHelp({
|
|
|
269
269
|
message.push(
|
|
270
270
|
linebreak(),
|
|
271
271
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
272
|
-
`v${"4.
|
|
272
|
+
`v${"4.10.0"}`
|
|
273
273
|
)} ${headline}`
|
|
274
274
|
);
|
|
275
275
|
}
|
|
@@ -8,6 +8,7 @@ import { renderEndpoint } from "../runtime/server/endpoint.js";
|
|
|
8
8
|
import { renderPage } from "../runtime/server/index.js";
|
|
9
9
|
import {
|
|
10
10
|
ASTRO_VERSION,
|
|
11
|
+
DEFAULT_404_COMPONENT,
|
|
11
12
|
REROUTE_DIRECTIVE_HEADER,
|
|
12
13
|
ROUTE_TYPE_HEADER,
|
|
13
14
|
clientAddressSymbol,
|
|
@@ -33,7 +34,10 @@ class RenderContext {
|
|
|
33
34
|
this.params = params;
|
|
34
35
|
this.url = url;
|
|
35
36
|
this.props = props;
|
|
37
|
+
this.originalRoute = routeData;
|
|
36
38
|
}
|
|
39
|
+
// The first route that this instance of the context attempts to render
|
|
40
|
+
originalRoute;
|
|
37
41
|
/**
|
|
38
42
|
* A flag that tells the render content if the rewriting was triggered
|
|
39
43
|
*/
|
|
@@ -95,18 +99,14 @@ class RenderContext {
|
|
|
95
99
|
const lastNext = async (ctx, payload) => {
|
|
96
100
|
if (payload) {
|
|
97
101
|
if (this.pipeline.manifest.rewritingEnabled) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
this.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
} finally {
|
|
108
|
-
this.isRewriting = true;
|
|
109
|
-
}
|
|
102
|
+
const [routeData, component] = await pipeline.tryRewrite(
|
|
103
|
+
payload,
|
|
104
|
+
this.request,
|
|
105
|
+
this.originalRoute
|
|
106
|
+
);
|
|
107
|
+
this.routeData = routeData;
|
|
108
|
+
componentInstance = component;
|
|
109
|
+
this.isRewriting = true;
|
|
110
110
|
} else {
|
|
111
111
|
this.pipeline.logger.warn(
|
|
112
112
|
"router",
|
|
@@ -173,29 +173,25 @@ class RenderContext {
|
|
|
173
173
|
const redirect = (path, status = 302) => new Response(null, { status, headers: { Location: path } });
|
|
174
174
|
const rewrite = async (reroutePayload) => {
|
|
175
175
|
pipeline.logger.debug("router", "Called rewriting to:", reroutePayload);
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
this.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
this.params = getParams(routeData, url.toString());
|
|
190
|
-
this.isRewriting = true;
|
|
191
|
-
return await this.render(component);
|
|
192
|
-
} catch (e) {
|
|
193
|
-
pipeline.logger.debug("router", "Rewrite failed.", e);
|
|
194
|
-
return new Response("Not found", {
|
|
195
|
-
status: 404,
|
|
196
|
-
statusText: "Not found"
|
|
197
|
-
});
|
|
176
|
+
const [routeData, component] = await pipeline.tryRewrite(
|
|
177
|
+
reroutePayload,
|
|
178
|
+
this.request,
|
|
179
|
+
this.originalRoute
|
|
180
|
+
);
|
|
181
|
+
this.routeData = routeData;
|
|
182
|
+
if (reroutePayload instanceof Request) {
|
|
183
|
+
this.request = reroutePayload;
|
|
184
|
+
} else {
|
|
185
|
+
this.request = this.#copyRequest(
|
|
186
|
+
new URL(routeData.pathname ?? routeData.route, this.url.origin),
|
|
187
|
+
this.request
|
|
188
|
+
);
|
|
198
189
|
}
|
|
190
|
+
this.url = new URL(this.request.url);
|
|
191
|
+
this.cookies = new AstroCookies(this.request);
|
|
192
|
+
this.params = getParams(routeData, url.toString());
|
|
193
|
+
this.isRewriting = true;
|
|
194
|
+
return await this.render(component);
|
|
199
195
|
};
|
|
200
196
|
return {
|
|
201
197
|
cookies,
|
|
@@ -330,30 +326,26 @@ class RenderContext {
|
|
|
330
326
|
return new Response(null, { status, headers: { Location: path } });
|
|
331
327
|
};
|
|
332
328
|
const rewrite = async (reroutePayload) => {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
this.
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
this.params = getParams(routeData, url.toString());
|
|
348
|
-
this.isRewriting = true;
|
|
349
|
-
return await this.render(component);
|
|
350
|
-
} catch (e) {
|
|
351
|
-
pipeline.logger.debug("router", "Rerouting failed, returning a 404.", e);
|
|
352
|
-
return new Response("Not found", {
|
|
353
|
-
status: 404,
|
|
354
|
-
statusText: "Not found"
|
|
355
|
-
});
|
|
329
|
+
pipeline.logger.debug("router", "Calling rewrite: ", reroutePayload);
|
|
330
|
+
const [routeData, component] = await pipeline.tryRewrite(
|
|
331
|
+
reroutePayload,
|
|
332
|
+
this.request,
|
|
333
|
+
this.originalRoute
|
|
334
|
+
);
|
|
335
|
+
this.routeData = routeData;
|
|
336
|
+
if (reroutePayload instanceof Request) {
|
|
337
|
+
this.request = reroutePayload;
|
|
338
|
+
} else {
|
|
339
|
+
this.request = this.#copyRequest(
|
|
340
|
+
new URL(routeData.pathname ?? routeData.route, this.url.origin),
|
|
341
|
+
this.request
|
|
342
|
+
);
|
|
356
343
|
}
|
|
344
|
+
this.url = new URL(this.request.url);
|
|
345
|
+
this.cookies = new AstroCookies(this.request);
|
|
346
|
+
this.params = getParams(routeData, url.toString());
|
|
347
|
+
this.isRewriting = true;
|
|
348
|
+
return await this.render(component);
|
|
357
349
|
};
|
|
358
350
|
return {
|
|
359
351
|
generator: astroStaticPartial.generator,
|
|
@@ -434,6 +426,31 @@ class RenderContext {
|
|
|
434
426
|
if (!i18n) return;
|
|
435
427
|
return this.#preferredLocaleList ??= computePreferredLocaleList(request, i18n.locales);
|
|
436
428
|
}
|
|
429
|
+
/**
|
|
430
|
+
* Utility function that creates a new `Request` with a new URL from an old `Request`.
|
|
431
|
+
*
|
|
432
|
+
* @param newUrl The new `URL`
|
|
433
|
+
* @param oldRequest The old `Request`
|
|
434
|
+
*/
|
|
435
|
+
#copyRequest(newUrl, oldRequest) {
|
|
436
|
+
return new Request(newUrl, {
|
|
437
|
+
method: oldRequest.method,
|
|
438
|
+
headers: oldRequest.headers,
|
|
439
|
+
body: oldRequest.body,
|
|
440
|
+
referrer: oldRequest.referrer,
|
|
441
|
+
referrerPolicy: oldRequest.referrerPolicy,
|
|
442
|
+
mode: oldRequest.mode,
|
|
443
|
+
credentials: oldRequest.credentials,
|
|
444
|
+
cache: oldRequest.cache,
|
|
445
|
+
redirect: oldRequest.redirect,
|
|
446
|
+
integrity: oldRequest.integrity,
|
|
447
|
+
signal: oldRequest.signal,
|
|
448
|
+
keepalive: oldRequest.keepalive,
|
|
449
|
+
// https://fetch.spec.whatwg.org/#dom-request-duplex
|
|
450
|
+
// @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
|
|
451
|
+
duplex: "half"
|
|
452
|
+
});
|
|
453
|
+
}
|
|
437
454
|
}
|
|
438
455
|
export {
|
|
439
456
|
RenderContext
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
import type { ManifestData } from '../../@types/astro.js';
|
|
1
|
+
import type { ManifestData, RouteData } from '../../@types/astro.js';
|
|
2
|
+
export declare const DEFAULT_404_ROUTE: RouteData;
|
|
2
3
|
export declare function ensure404Route(manifest: ManifestData): ManifestData;
|
|
4
|
+
export declare function default404Page({ pathname }: {
|
|
5
|
+
pathname: string;
|
|
6
|
+
}): Promise<Response>;
|
|
7
|
+
export declare namespace default404Page {
|
|
8
|
+
var isAstroComponentFactory: boolean;
|
|
9
|
+
}
|
|
@@ -1,21 +1,38 @@
|
|
|
1
|
+
import notFoundTemplate from "../../template/4xx.js";
|
|
1
2
|
import { DEFAULT_404_COMPONENT } from "../constants.js";
|
|
3
|
+
const DEFAULT_404_ROUTE = {
|
|
4
|
+
component: DEFAULT_404_COMPONENT,
|
|
5
|
+
generate: () => "",
|
|
6
|
+
params: [],
|
|
7
|
+
pattern: /\/404/,
|
|
8
|
+
prerender: false,
|
|
9
|
+
pathname: "/404",
|
|
10
|
+
segments: [[{ content: "404", dynamic: false, spread: false }]],
|
|
11
|
+
type: "page",
|
|
12
|
+
route: "/404",
|
|
13
|
+
fallbackRoutes: [],
|
|
14
|
+
isIndex: false
|
|
15
|
+
};
|
|
2
16
|
function ensure404Route(manifest) {
|
|
3
17
|
if (!manifest.routes.some((route) => route.route === "/404")) {
|
|
4
|
-
manifest.routes.push(
|
|
5
|
-
component: DEFAULT_404_COMPONENT,
|
|
6
|
-
generate: () => "",
|
|
7
|
-
params: [],
|
|
8
|
-
pattern: /\/404/,
|
|
9
|
-
prerender: false,
|
|
10
|
-
segments: [[{ content: "404", dynamic: false, spread: false }]],
|
|
11
|
-
type: "page",
|
|
12
|
-
route: "/404",
|
|
13
|
-
fallbackRoutes: [],
|
|
14
|
-
isIndex: false
|
|
15
|
-
});
|
|
18
|
+
manifest.routes.push(DEFAULT_404_ROUTE);
|
|
16
19
|
}
|
|
17
20
|
return manifest;
|
|
18
21
|
}
|
|
22
|
+
async function default404Page({ pathname }) {
|
|
23
|
+
return new Response(
|
|
24
|
+
notFoundTemplate({
|
|
25
|
+
statusCode: 404,
|
|
26
|
+
title: "Not found",
|
|
27
|
+
tabTitle: "404: Not Found",
|
|
28
|
+
pathname
|
|
29
|
+
}),
|
|
30
|
+
{ status: 404, headers: { "Content-Type": "text/html; charset=utf-8" } }
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
default404Page.isAstroComponentFactory = true;
|
|
19
34
|
export {
|
|
35
|
+
DEFAULT_404_ROUTE,
|
|
36
|
+
default404Page,
|
|
20
37
|
ensure404Route
|
|
21
38
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BooleanField, BooleanFieldInput, NumberField, NumberFieldInput, StringField, StringFieldInput } from './schema.js';
|
|
2
|
+
/**
|
|
3
|
+
* Return a valid env field to use in this Astro config for `experimental.env.schema`.
|
|
4
|
+
*/
|
|
5
|
+
export declare const envField: {
|
|
6
|
+
string: (options: StringFieldInput) => StringField;
|
|
7
|
+
number: (options: NumberFieldInput) => NumberField;
|
|
8
|
+
boolean: (options: BooleanFieldInput) => BooleanField;
|
|
9
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const envField = {
|
|
2
|
+
string: (options) => ({
|
|
3
|
+
...options,
|
|
4
|
+
type: "string"
|
|
5
|
+
}),
|
|
6
|
+
number: (options) => ({
|
|
7
|
+
...options,
|
|
8
|
+
type: "number"
|
|
9
|
+
}),
|
|
10
|
+
boolean: (options) => ({
|
|
11
|
+
...options,
|
|
12
|
+
type: "boolean"
|
|
13
|
+
})
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
envField
|
|
17
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const VIRTUAL_MODULES_IDS: {
|
|
2
|
+
client: string;
|
|
3
|
+
server: string;
|
|
4
|
+
internal: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const VIRTUAL_MODULES_IDS_VALUES: Set<string>;
|
|
7
|
+
export declare const VIRTUAL_MODULE_SETUP_ID = "astro:env/setup";
|
|
8
|
+
export declare const PUBLIC_PREFIX = "PUBLIC_";
|
|
9
|
+
export declare const ENV_TYPES_FILE = "env.d.ts";
|
|
10
|
+
export declare const MODULE_TEMPLATE_URL: URL;
|
|
11
|
+
export declare const TYPES_TEMPLATE_URL: URL;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const VIRTUAL_MODULES_IDS = {
|
|
2
|
+
client: "astro:env/client",
|
|
3
|
+
server: "astro:env/server",
|
|
4
|
+
internal: "virtual:astro:env/internal"
|
|
5
|
+
};
|
|
6
|
+
const VIRTUAL_MODULES_IDS_VALUES = new Set(Object.values(VIRTUAL_MODULES_IDS));
|
|
7
|
+
const VIRTUAL_MODULE_SETUP_ID = "astro:env/setup";
|
|
8
|
+
const PUBLIC_PREFIX = "PUBLIC_";
|
|
9
|
+
const ENV_TYPES_FILE = "env.d.ts";
|
|
10
|
+
const PKG_BASE = new URL("../../", import.meta.url);
|
|
11
|
+
const MODULE_TEMPLATE_URL = new URL("templates/env/module.mjs", PKG_BASE);
|
|
12
|
+
const TYPES_TEMPLATE_URL = new URL("templates/env/types.d.ts", PKG_BASE);
|
|
13
|
+
export {
|
|
14
|
+
ENV_TYPES_FILE,
|
|
15
|
+
MODULE_TEMPLATE_URL,
|
|
16
|
+
PUBLIC_PREFIX,
|
|
17
|
+
TYPES_TEMPLATE_URL,
|
|
18
|
+
VIRTUAL_MODULES_IDS,
|
|
19
|
+
VIRTUAL_MODULES_IDS_VALUES,
|
|
20
|
+
VIRTUAL_MODULE_SETUP_ID
|
|
21
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AstroError, AstroErrorData } from '../core/errors/index.js';
|
|
2
|
+
export { validateEnvVariable } from './validators.js';
|
|
3
|
+
export type GetEnv = (key: string) => string | undefined;
|
|
4
|
+
export declare function setGetEnv(fn: GetEnv): void;
|
|
5
|
+
export declare function getEnv(...args: Parameters<GetEnv>): string | undefined;
|
|
6
|
+
export declare function createInvalidVariableError(...args: Parameters<typeof AstroErrorData.EnvInvalidVariable.message>): AstroError;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
2
|
+
import { validateEnvVariable } from "./validators.js";
|
|
3
|
+
let _getEnv = (key) => process.env[key];
|
|
4
|
+
function setGetEnv(fn) {
|
|
5
|
+
_getEnv = fn;
|
|
6
|
+
}
|
|
7
|
+
function getEnv(...args) {
|
|
8
|
+
return _getEnv(...args);
|
|
9
|
+
}
|
|
10
|
+
function createInvalidVariableError(...args) {
|
|
11
|
+
return new AstroError({
|
|
12
|
+
...AstroErrorData.EnvInvalidVariable,
|
|
13
|
+
message: AstroErrorData.EnvInvalidVariable.message(...args)
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
createInvalidVariableError,
|
|
18
|
+
getEnv,
|
|
19
|
+
setGetEnv,
|
|
20
|
+
validateEnvVariable
|
|
21
|
+
};
|