astro 7.2.2 → 7.2.3
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/dist/actions/handler.d.ts +6 -12
- package/dist/actions/handler.js +30 -40
- package/dist/actions/load.d.ts +12 -0
- package/dist/actions/load.js +55 -0
- package/dist/actions/runtime/entrypoints/server.js +5 -4
- package/dist/actions/runtime/server.js +8 -6
- package/dist/assets/fonts/providers/index.d.ts +1 -1
- package/dist/assets/fonts/providers/index.js +2 -12
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/container/environment.d.ts +20 -0
- package/dist/container/environment.js +106 -0
- package/dist/container/index.js +65 -32
- package/dist/content/content-layer.js +3 -3
- package/dist/content/data-store-writer.d.ts +7 -10
- package/dist/content/data-store-writer.js +62 -27
- package/dist/content/data-store.d.ts +20 -3
- package/dist/content/data-store.js +28 -7
- package/dist/content/mutable-data-store.js +15 -10
- package/dist/content/runtime.d.ts +3 -2
- package/dist/content/runtime.js +43 -26
- package/dist/core/app/app.d.ts +0 -2
- package/dist/core/app/app.js +0 -7
- package/dist/core/app/base.d.ts +32 -20
- package/dist/core/app/base.js +76 -66
- package/dist/core/app/dev-facade.d.ts +27 -0
- package/dist/core/app/dev-facade.js +51 -0
- package/dist/core/app/entrypoints/index.d.ts +0 -1
- package/dist/core/app/entrypoints/index.js +0 -2
- package/dist/core/app/entrypoints/virtual/dev.js +24 -19
- package/dist/core/app/node.js +13 -14
- package/dist/core/app/prepare-response.d.ts +1 -1
- package/dist/core/app/validate-headers.js +7 -3
- package/dist/core/build/app.d.ts +31 -6
- package/dist/core/build/app.js +31 -13
- package/dist/core/build/environment.d.ts +25 -0
- package/dist/core/build/environment.js +157 -0
- package/dist/core/cache/handler.d.ts +13 -7
- package/dist/core/cache/handler.js +55 -51
- package/dist/core/cache/provider.d.ts +4 -0
- package/dist/core/cache/provider.js +15 -0
- package/dist/core/constants.d.ts +0 -11
- package/dist/core/constants.js +1 -5
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/environment/dev-nonrunnable.d.ts +6 -0
- package/dist/core/environment/dev-nonrunnable.js +170 -0
- package/dist/core/environment/index.d.ts +90 -0
- package/dist/core/environment/index.js +12 -0
- package/dist/core/environment/production.d.ts +6 -0
- package/dist/core/environment/production.js +117 -0
- package/dist/core/errors/build-handler.d.ts +5 -10
- package/dist/core/errors/build-handler.js +11 -17
- package/dist/core/errors/default-handler.d.ts +4 -9
- package/dist/core/errors/default-handler.js +92 -107
- package/dist/core/errors/dev-handler.d.ts +7 -11
- package/dist/core/errors/dev-handler.js +71 -69
- package/dist/core/errors/errors-data.d.ts +18 -0
- package/dist/core/errors/errors-data.js +7 -0
- package/dist/core/errors/handler.d.ts +22 -3
- package/dist/core/errors/handler.js +25 -0
- package/dist/core/fetch/default-handler.d.ts +15 -8
- package/dist/core/fetch/default-handler.js +12 -34
- package/dist/core/fetch/features.d.ts +23 -0
- package/dist/core/fetch/features.js +27 -0
- package/dist/core/fetch/fetch-state.d.ts +52 -7
- package/dist/core/fetch/fetch-state.js +92 -81
- package/dist/core/fetch/index.d.ts +9 -2
- package/dist/core/fetch/index.js +18 -79
- package/dist/core/fetch/vite-plugin.js +2 -1
- package/dist/core/i18n/handler.d.ts +28 -13
- package/dist/core/i18n/handler.js +100 -100
- package/dist/core/logger/manifest-logger.d.ts +31 -0
- package/dist/core/logger/manifest-logger.js +37 -0
- package/dist/core/manifest/ambient-source.d.ts +2 -0
- package/dist/core/manifest/ambient-source.js +4 -0
- package/dist/core/manifest/ambient.d.ts +16 -0
- package/dist/core/manifest/ambient.js +22 -0
- package/dist/core/manifest/derived.d.ts +3 -0
- package/dist/core/manifest/derived.js +10 -0
- package/dist/core/manifest/memo.d.ts +31 -0
- package/dist/core/manifest/memo.js +47 -0
- package/dist/core/messages/runtime.js +1 -1
- package/dist/core/middleware/astro-middleware.d.ts +25 -35
- package/dist/core/middleware/astro-middleware.js +61 -81
- package/dist/core/middleware/load.d.ts +19 -0
- package/dist/core/middleware/load.js +36 -0
- package/dist/core/middleware/sequence.js +15 -7
- package/dist/core/pages/handler.d.ts +18 -25
- package/dist/core/pages/handler.js +68 -84
- package/dist/core/redirects/render.js +3 -8
- package/dist/core/render/index.d.ts +0 -1
- package/dist/core/render/index.js +0 -2
- package/dist/core/render/route-cache.d.ts +6 -1
- package/dist/core/render/route-cache.js +11 -1
- package/dist/core/rewrites/handler.d.ts +4 -6
- package/dist/core/rewrites/handler.js +19 -20
- package/dist/core/routing/default.d.ts +2 -0
- package/dist/core/routing/default.js +7 -1
- package/dist/core/routing/dev.d.ts +1 -3
- package/dist/core/routing/dev.js +12 -5
- package/dist/core/routing/handler.d.ts +6 -16
- package/dist/core/routing/handler.js +126 -164
- package/dist/core/routing/helpers.d.ts +7 -1
- package/dist/core/routing/helpers.js +21 -0
- package/dist/core/routing/match-request.d.ts +10 -0
- package/dist/core/routing/match-request.js +57 -0
- package/dist/core/routing/route-table.d.ts +34 -0
- package/dist/core/routing/route-table.js +41 -0
- package/dist/core/routing/trailing-slash-handler.d.ts +4 -14
- package/dist/core/routing/trailing-slash-handler.js +39 -50
- package/dist/core/server-islands/mappings.d.ts +6 -0
- package/dist/core/server-islands/mappings.js +12 -0
- package/dist/core/session/driver.d.ts +4 -0
- package/dist/core/session/driver.js +14 -0
- package/dist/core/session/handler.d.ts +1 -1
- package/dist/core/session/handler.js +8 -8
- package/dist/core/session/provider-disabled.js +2 -2
- package/dist/entrypoints/prerender.js +5 -1
- package/dist/i18n/middleware.d.ts +4 -4
- package/dist/i18n/middleware.js +3 -3
- package/dist/manifest/serialized.d.ts +1 -0
- package/dist/manifest/serialized.js +9 -2
- package/dist/runtime/prerender/static-paths.d.ts +14 -2
- package/dist/runtime/prerender/static-paths.js +4 -3
- package/dist/types/public/config.d.ts +433 -241
- package/dist/vite-plugin-app/createAstroServerApp.js +22 -18
- package/dist/vite-plugin-app/environment.d.ts +18 -0
- package/dist/vite-plugin-app/environment.js +210 -0
- package/dist/vite-plugin-app/handle-request.d.ts +30 -0
- package/dist/vite-plugin-app/handle-request.js +129 -0
- package/dist/vite-plugin-app/index.d.ts +1 -1
- package/dist/vite-plugin-app/index.js +1 -1
- package/package.json +14 -7
- package/src/core/README.md +37 -0
- package/src/core/manifest/ambient-source.ts +9 -0
- package/src/types/README.md +5 -0
- package/dist/container/pipeline.d.ts +0 -14
- package/dist/container/pipeline.js +0 -78
- package/dist/core/app/dev/app.d.ts +0 -31
- package/dist/core/app/dev/app.js +0 -80
- package/dist/core/app/dev/pipeline.d.ts +0 -17
- package/dist/core/app/dev/pipeline.js +0 -133
- package/dist/core/app/pipeline.d.ts +0 -14
- package/dist/core/app/pipeline.js +0 -123
- package/dist/core/base-pipeline.d.ts +0 -183
- package/dist/core/base-pipeline.js +0 -293
- package/dist/core/build/pipeline.d.ts +0 -38
- package/dist/core/build/pipeline.js +0 -202
- package/dist/vite-plugin-app/app.d.ts +0 -62
- package/dist/vite-plugin-app/app.js +0 -237
- package/dist/vite-plugin-app/pipeline.d.ts +0 -25
- package/dist/vite-plugin-app/pipeline.js +0 -189
|
@@ -10,11 +10,9 @@ import { createCallAction, createGetActionResult, hasActionPayload } from "../..
|
|
|
10
10
|
import { AstroCookies } from "../cookies/index.js";
|
|
11
11
|
import { Slots } from "../render/index.js";
|
|
12
12
|
import {
|
|
13
|
-
appSymbol,
|
|
14
13
|
ASTRO_GENERATOR,
|
|
15
14
|
fetchStateSymbol,
|
|
16
15
|
originPathnameSymbol,
|
|
17
|
-
pipelineSymbol,
|
|
18
16
|
responseSentSymbol
|
|
19
17
|
} from "../constants.js";
|
|
20
18
|
import { normalizeCspResourceEntry, pushDirective } from "../csp/runtime.js";
|
|
@@ -27,7 +25,7 @@ import {
|
|
|
27
25
|
computePreferredLocaleList as computePreferredLocaleListUtil
|
|
28
26
|
} from "../../i18n/utils.js";
|
|
29
27
|
import { getParams, getProps } from "../render/index.js";
|
|
30
|
-
import {
|
|
28
|
+
import { executeRewrite } from "../rewrites/handler.js";
|
|
31
29
|
import { isRoute404or500, isRouteServerIsland } from "../routing/match.js";
|
|
32
30
|
import { MultiLevelEncodingError, validateAndDecodePathname } from "../util/pathname.js";
|
|
33
31
|
import { getOriginPathname, setOriginPathname } from "../routing/rewrite.js";
|
|
@@ -35,6 +33,12 @@ import { computePathnameFromDomain } from "../i18n/domain.js";
|
|
|
35
33
|
import { getCustom404Route, routeHasHtmlExtension } from "../routing/helpers.js";
|
|
36
34
|
import { getRenderOptions } from "../app/render-options.js";
|
|
37
35
|
import { getFirstForwardedValue, validateForwardedHeaders } from "../app/validate-headers.js";
|
|
36
|
+
import { getEnvironment } from "../environment/index.js";
|
|
37
|
+
import { getLogger } from "../logger/manifest-logger.js";
|
|
38
|
+
import { getSite } from "../manifest/derived.js";
|
|
39
|
+
import { getRouteCache } from "../render/route-cache.js";
|
|
40
|
+
import { getRouteTable, matchAllRoutes, matchRoute } from "../routing/route-table.js";
|
|
41
|
+
import { getServerIslands } from "../server-islands/mappings.js";
|
|
38
42
|
function getFetchStateFromAPIContext(context) {
|
|
39
43
|
const state = context[fetchStateSymbol];
|
|
40
44
|
if (!state) {
|
|
@@ -45,7 +49,27 @@ function getFetchStateFromAPIContext(context) {
|
|
|
45
49
|
return state;
|
|
46
50
|
}
|
|
47
51
|
class FetchState {
|
|
48
|
-
|
|
52
|
+
/** The manifest — the single ambient source of static, build-time data. */
|
|
53
|
+
manifest;
|
|
54
|
+
/** The manifest's identity-stable logger, captured once at construction. */
|
|
55
|
+
logger;
|
|
56
|
+
/**
|
|
57
|
+
* Whether page renders stream. From the facade hooks on the fast path,
|
|
58
|
+
* else the environment's default.
|
|
59
|
+
*/
|
|
60
|
+
streaming;
|
|
61
|
+
/**
|
|
62
|
+
* Internal facade hook: late-bound `app.renderError` dispatch. Undefined on
|
|
63
|
+
* bare and custom-handler paths — those fall through to the environment's
|
|
64
|
+
* error strategy (`renderErrorPage`).
|
|
65
|
+
*/
|
|
66
|
+
renderError;
|
|
67
|
+
/**
|
|
68
|
+
* Internal facade hook: late-bound `app.logThisRequest` dispatch. Undefined
|
|
69
|
+
* on bare and custom-handler paths — those fall through to the
|
|
70
|
+
* environment's `logRequest` behavior.
|
|
71
|
+
*/
|
|
72
|
+
logRequest;
|
|
49
73
|
/**
|
|
50
74
|
* The request to render. Mutated during rewrites so subsequent renders
|
|
51
75
|
* see the rewritten URL.
|
|
@@ -55,7 +79,7 @@ class FetchState {
|
|
|
55
79
|
/**
|
|
56
80
|
* The pathname to use for routing and rendering. Starts out as the raw,
|
|
57
81
|
* base-stripped, decoded pathname from the request. May be further
|
|
58
|
-
* normalized by `
|
|
82
|
+
* normalized by `handleRequest` after routeData is known (in dev, when
|
|
59
83
|
* the matched route has no `.html` extension, `.html` / `/index.html`
|
|
60
84
|
* suffixes are stripped).
|
|
61
85
|
*/
|
|
@@ -82,7 +106,7 @@ class FetchState {
|
|
|
82
106
|
response;
|
|
83
107
|
/**
|
|
84
108
|
* Default HTTP status for the rendered response. Callers override
|
|
85
|
-
* before rendering runs (e.g. `
|
|
109
|
+
* before rendering runs (e.g. `handleRequest` sets this from
|
|
86
110
|
* `BaseApp.getDefaultStatusCode`; error handlers set `404` / `500`).
|
|
87
111
|
*/
|
|
88
112
|
status = 200;
|
|
@@ -145,8 +169,6 @@ class FetchState {
|
|
|
145
169
|
result;
|
|
146
170
|
/** Initial props (from container/error handler). */
|
|
147
171
|
initialProps = {};
|
|
148
|
-
/** Rewrites handler instance. Lazy-initialized on first rewrite(). */
|
|
149
|
-
#rewrites;
|
|
150
172
|
/** Memoized Astro page partial. */
|
|
151
173
|
#astroPagePartial;
|
|
152
174
|
/**
|
|
@@ -162,8 +184,12 @@ class FetchState {
|
|
|
162
184
|
#preferredLocale;
|
|
163
185
|
/** Memoized preferred locale list. */
|
|
164
186
|
#preferredLocaleList;
|
|
165
|
-
constructor(
|
|
166
|
-
this.
|
|
187
|
+
constructor(manifest, request, options, hooks) {
|
|
188
|
+
this.manifest = manifest;
|
|
189
|
+
this.logger = getLogger(manifest);
|
|
190
|
+
this.streaming = hooks?.streaming ?? getEnvironment(manifest).defaultStreaming(manifest);
|
|
191
|
+
this.renderError = hooks?.renderError;
|
|
192
|
+
this.logRequest = hooks?.logRequest;
|
|
167
193
|
this.request = request;
|
|
168
194
|
options ??= getRenderOptions(request);
|
|
169
195
|
this.routeData = options?.routeData;
|
|
@@ -190,10 +216,10 @@ class FetchState {
|
|
|
190
216
|
const domainPathname = computePathnameFromDomain(
|
|
191
217
|
request,
|
|
192
218
|
url,
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
219
|
+
manifest.i18n,
|
|
220
|
+
manifest.base,
|
|
221
|
+
manifest.trailingSlash,
|
|
222
|
+
this.logger,
|
|
197
223
|
pathname
|
|
198
224
|
);
|
|
199
225
|
if (domainPathname) {
|
|
@@ -207,33 +233,31 @@ class FetchState {
|
|
|
207
233
|
this.locals = options?.locals ?? {};
|
|
208
234
|
this.url = url;
|
|
209
235
|
this.cookies = new AstroCookies(request);
|
|
210
|
-
if (
|
|
236
|
+
if (manifest.allowedDomains && manifest.allowedDomains.length > 0 && !this.routeData?.prerender) {
|
|
211
237
|
this.#applyForwardedHeaders();
|
|
212
238
|
}
|
|
213
239
|
if (!Reflect.get(this.request, originPathnameSymbol)) {
|
|
214
|
-
setOriginPathname(
|
|
215
|
-
this.request,
|
|
216
|
-
this.pathname,
|
|
217
|
-
pipeline.manifest.trailingSlash,
|
|
218
|
-
pipeline.manifest.buildFormat
|
|
219
|
-
);
|
|
240
|
+
setOriginPathname(this.request, this.pathname, manifest.trailingSlash, manifest.buildFormat);
|
|
220
241
|
}
|
|
221
242
|
this.#resolveRouteData();
|
|
222
243
|
}
|
|
223
244
|
/**
|
|
224
|
-
* Triggers a rewrite. Delegates to the
|
|
245
|
+
* Triggers a rewrite. Delegates to the rewrites handler module.
|
|
225
246
|
*/
|
|
226
247
|
rewrite(payload) {
|
|
227
|
-
return (this
|
|
248
|
+
return executeRewrite(this, payload);
|
|
228
249
|
}
|
|
229
250
|
/**
|
|
230
251
|
* Creates the SSR result for the current page render.
|
|
231
252
|
*/
|
|
232
253
|
async createResult(mod, ctx) {
|
|
233
|
-
const
|
|
234
|
-
const
|
|
254
|
+
const manifest = this.manifest;
|
|
255
|
+
const env = getEnvironment(manifest);
|
|
256
|
+
const { clientDirectives, inlinedScripts, compressHTML } = manifest;
|
|
257
|
+
const renderers = env.getRenderers(manifest);
|
|
258
|
+
const resolve = (specifier) => env.resolve(manifest, specifier);
|
|
235
259
|
const routeData = this.routeData;
|
|
236
|
-
const { links, scripts, styles } = await
|
|
260
|
+
const { links, scripts, styles } = await env.headElements(manifest, routeData);
|
|
237
261
|
const extraStyleHashes = [];
|
|
238
262
|
const extraScriptHashes = [];
|
|
239
263
|
const shouldInjectCspMetaTags = this.shouldInjectCspMetaTags ?? manifest.shouldInjectCspMetaTags;
|
|
@@ -246,7 +270,7 @@ class FetchState {
|
|
|
246
270
|
extraScriptHashes.push(await generateCspDigest(script.children, cspAlgorithm));
|
|
247
271
|
}
|
|
248
272
|
}
|
|
249
|
-
const componentMetadata = await
|
|
273
|
+
const componentMetadata = await env.componentMetadata(manifest, routeData) ?? manifest.componentMetadata;
|
|
250
274
|
const headers = new Headers({ "Content-Type": "text/html" });
|
|
251
275
|
const partial = typeof this.partial === "boolean" ? this.partial : Boolean(mod.partial);
|
|
252
276
|
const actionResult = hasActionPayload(this.locals) ? deserializeActionResult(this.locals._actionPayload.actionResult) : void 0;
|
|
@@ -286,7 +310,7 @@ class FetchState {
|
|
|
286
310
|
styles,
|
|
287
311
|
actionResult,
|
|
288
312
|
async getServerIslandNameMap() {
|
|
289
|
-
const serverIslands = await
|
|
313
|
+
const serverIslands = await getServerIslands(manifest);
|
|
290
314
|
return serverIslands.serverIslandNameMap ?? /* @__PURE__ */ new Map();
|
|
291
315
|
},
|
|
292
316
|
key: manifest.key,
|
|
@@ -355,11 +379,7 @@ class FetchState {
|
|
|
355
379
|
Object.defineProperty(Astro, "slots", {
|
|
356
380
|
get: () => {
|
|
357
381
|
if (!_slots) {
|
|
358
|
-
_slots = new Slots(
|
|
359
|
-
result,
|
|
360
|
-
slotValues,
|
|
361
|
-
this.pipeline.logger
|
|
362
|
-
);
|
|
382
|
+
_slots = new Slots(result, slotValues, this.logger);
|
|
363
383
|
}
|
|
364
384
|
return _slots;
|
|
365
385
|
}
|
|
@@ -371,7 +391,7 @@ class FetchState {
|
|
|
371
391
|
*/
|
|
372
392
|
createAstroPagePartial(result, apiContext) {
|
|
373
393
|
const state = this;
|
|
374
|
-
const { cookies, locals, params,
|
|
394
|
+
const { cookies, locals, params, logger, url } = this;
|
|
375
395
|
const { response } = result;
|
|
376
396
|
const redirect = (path, status = 302) => {
|
|
377
397
|
if (state.request[responseSentSymbol]) {
|
|
@@ -408,7 +428,7 @@ class FetchState {
|
|
|
408
428
|
rewrite,
|
|
409
429
|
request: this.request,
|
|
410
430
|
response,
|
|
411
|
-
site:
|
|
431
|
+
site: getSite(this.manifest),
|
|
412
432
|
getActionResult: createGetActionResult(locals),
|
|
413
433
|
get callAction() {
|
|
414
434
|
return callAction;
|
|
@@ -423,13 +443,13 @@ class FetchState {
|
|
|
423
443
|
get logger() {
|
|
424
444
|
return {
|
|
425
445
|
info(msg) {
|
|
426
|
-
|
|
446
|
+
logger.info(null, msg);
|
|
427
447
|
},
|
|
428
448
|
warn(msg) {
|
|
429
|
-
|
|
449
|
+
logger.warn(null, msg);
|
|
430
450
|
},
|
|
431
451
|
error(msg) {
|
|
432
|
-
|
|
452
|
+
logger.error(null, msg);
|
|
433
453
|
}
|
|
434
454
|
};
|
|
435
455
|
}
|
|
@@ -438,7 +458,7 @@ class FetchState {
|
|
|
438
458
|
return partial;
|
|
439
459
|
}
|
|
440
460
|
getClientAddress() {
|
|
441
|
-
const {
|
|
461
|
+
const { clientAddress } = this;
|
|
442
462
|
const routeData = this.routeData;
|
|
443
463
|
if (routeData.prerender) {
|
|
444
464
|
throw new AstroError({
|
|
@@ -449,10 +469,10 @@ class FetchState {
|
|
|
449
469
|
if (clientAddress) {
|
|
450
470
|
return clientAddress;
|
|
451
471
|
}
|
|
452
|
-
if (
|
|
472
|
+
if (this.manifest.adapterName) {
|
|
453
473
|
throw new AstroError({
|
|
454
474
|
...AstroErrorData.ClientAddressNotAvailable,
|
|
455
|
-
message: AstroErrorData.ClientAddressNotAvailable.message(
|
|
475
|
+
message: AstroErrorData.ClientAddressNotAvailable.message(this.manifest.adapterName)
|
|
456
476
|
});
|
|
457
477
|
}
|
|
458
478
|
throw new AstroError(AstroErrorData.StaticClientAddressNotAvailable);
|
|
@@ -462,10 +482,9 @@ class FetchState {
|
|
|
462
482
|
}
|
|
463
483
|
getCsp() {
|
|
464
484
|
const state = this;
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
pipeline.logger.warn(
|
|
485
|
+
if (!this.manifest.csp) {
|
|
486
|
+
if (getEnvironment(this.manifest).runtimeMode === "production") {
|
|
487
|
+
this.logger.warn(
|
|
469
488
|
"csp",
|
|
470
489
|
`context.csp was used when rendering the route ${colors.green(state.routeData.route)}, but CSP was not configured. For more information, see https://docs.astro.build/en/reference/configuration-reference/#securitycsp`
|
|
471
490
|
);
|
|
@@ -489,7 +508,7 @@ class FetchState {
|
|
|
489
508
|
warnedFallback.add(key);
|
|
490
509
|
const general = `${family}-src`;
|
|
491
510
|
const specific = `${general}-${kind === "element" ? "elem" : "attr"}`;
|
|
492
|
-
|
|
511
|
+
state.logger.warn(
|
|
493
512
|
"csp",
|
|
494
513
|
`A resource was added to \`${specific}\`, but \`${general}\` also defines custom resources (${defaultResources.join(
|
|
495
514
|
" "
|
|
@@ -523,7 +542,7 @@ class FetchState {
|
|
|
523
542
|
computeCurrentLocale() {
|
|
524
543
|
const {
|
|
525
544
|
url,
|
|
526
|
-
|
|
545
|
+
manifest: { i18n },
|
|
527
546
|
routeData
|
|
528
547
|
} = this;
|
|
529
548
|
if (!i18n || !routeData) return;
|
|
@@ -567,7 +586,7 @@ class FetchState {
|
|
|
567
586
|
}
|
|
568
587
|
computePreferredLocale() {
|
|
569
588
|
const {
|
|
570
|
-
|
|
589
|
+
manifest: { i18n },
|
|
571
590
|
request
|
|
572
591
|
} = this;
|
|
573
592
|
if (!i18n) return;
|
|
@@ -575,7 +594,7 @@ class FetchState {
|
|
|
575
594
|
}
|
|
576
595
|
computePreferredLocaleList() {
|
|
577
596
|
const {
|
|
578
|
-
|
|
597
|
+
manifest: { i18n },
|
|
579
598
|
request
|
|
580
599
|
} = this;
|
|
581
600
|
if (!i18n) return;
|
|
@@ -589,7 +608,7 @@ class FetchState {
|
|
|
589
608
|
async loadComponentInstance() {
|
|
590
609
|
if (this.componentInstance) return this.componentInstance;
|
|
591
610
|
if (this.#componentInstancePromise) return this.#componentInstancePromise;
|
|
592
|
-
this.#componentInstancePromise = this.
|
|
611
|
+
this.#componentInstancePromise = getEnvironment(this.manifest).getComponentByRoute(this.manifest, this.routeData).then((mod) => {
|
|
593
612
|
this.componentInstance = mod;
|
|
594
613
|
return mod;
|
|
595
614
|
});
|
|
@@ -666,7 +685,7 @@ class FetchState {
|
|
|
666
685
|
get() {
|
|
667
686
|
if (!warned) {
|
|
668
687
|
warned = true;
|
|
669
|
-
state.
|
|
688
|
+
state.logger.warn(
|
|
670
689
|
"session",
|
|
671
690
|
"`Astro.session` was accessed but no session storage is configured. Either configure the storage manually or use an adapter that provides session storage. For more information, see https://docs.astro.build/en/guides/sessions/"
|
|
672
691
|
);
|
|
@@ -707,15 +726,14 @@ class FetchState {
|
|
|
707
726
|
}
|
|
708
727
|
}
|
|
709
728
|
#resolveRouteData() {
|
|
710
|
-
const pipeline = this.pipeline;
|
|
711
729
|
if (this.routeData) {
|
|
712
730
|
this.#stripHtmlExtension();
|
|
713
731
|
return;
|
|
714
732
|
}
|
|
715
|
-
const matched =
|
|
716
|
-
if (matched && matched.prerender &&
|
|
733
|
+
const matched = matchRoute(this.manifest, this.pathname);
|
|
734
|
+
if (matched && matched.prerender && this.manifest.serverLike) {
|
|
717
735
|
if (matched.params.length > 0) {
|
|
718
|
-
const allMatches =
|
|
736
|
+
const allMatches = matchAllRoutes(this.manifest, this.pathname);
|
|
719
737
|
this.routeData = allMatches.find((r) => !r.prerender);
|
|
720
738
|
} else {
|
|
721
739
|
this.routeData = void 0;
|
|
@@ -723,23 +741,23 @@ class FetchState {
|
|
|
723
741
|
} else {
|
|
724
742
|
this.routeData = matched;
|
|
725
743
|
}
|
|
726
|
-
|
|
727
|
-
|
|
744
|
+
this.logger.debug("router", "Astro matched the following route for " + this.request.url);
|
|
745
|
+
this.logger.debug("router", "RouteData:\n" + this.routeData);
|
|
728
746
|
if (!this.routeData) {
|
|
729
|
-
const custom404 = getCustom404Route(
|
|
747
|
+
const custom404 = getCustom404Route(getRouteTable(this.manifest));
|
|
730
748
|
if (custom404 && !custom404.prerender) {
|
|
731
749
|
this.routeData = custom404;
|
|
732
750
|
}
|
|
733
751
|
}
|
|
734
752
|
if (!this.routeData) {
|
|
735
|
-
|
|
736
|
-
|
|
753
|
+
this.logger.debug("router", "Astro hasn't found routes that match " + this.request.url);
|
|
754
|
+
this.logger.debug("router", "Here's the available routes:\n", getRouteTable(this.manifest));
|
|
737
755
|
return;
|
|
738
756
|
}
|
|
739
757
|
this.#stripHtmlExtension();
|
|
740
758
|
}
|
|
741
759
|
/**
|
|
742
|
-
* Strips the
|
|
760
|
+
* Strips the manifest's base from a normalized request pathname and prepends
|
|
743
761
|
* a forward slash.
|
|
744
762
|
*
|
|
745
763
|
* Mirrors `BaseApp.removeBase`, including the
|
|
@@ -748,7 +766,7 @@ class FetchState {
|
|
|
748
766
|
*/
|
|
749
767
|
#computePathname(normalizedPathname) {
|
|
750
768
|
let pathname = collapseDuplicateLeadingSlashes(normalizedPathname);
|
|
751
|
-
const base = this.
|
|
769
|
+
const base = this.manifest.base;
|
|
752
770
|
if (pathname.startsWith(base)) {
|
|
753
771
|
const baseWithoutTrailingSlash = removeTrailingForwardSlash(base);
|
|
754
772
|
pathname = pathname.slice(baseWithoutTrailingSlash.length + 1);
|
|
@@ -766,7 +784,7 @@ class FetchState {
|
|
|
766
784
|
if (e instanceof MultiLevelEncodingError) {
|
|
767
785
|
this.invalidEncoding = true;
|
|
768
786
|
} else {
|
|
769
|
-
this.
|
|
787
|
+
this.logger.error(null, e.toString());
|
|
770
788
|
}
|
|
771
789
|
}
|
|
772
790
|
return collapseDuplicateSlashes(pathname);
|
|
@@ -782,7 +800,7 @@ class FetchState {
|
|
|
782
800
|
*/
|
|
783
801
|
#applyForwardedHeaders() {
|
|
784
802
|
const headers = this.request.headers;
|
|
785
|
-
const allowedDomains = this.
|
|
803
|
+
const allowedDomains = this.manifest.allowedDomains;
|
|
786
804
|
const validated = validateForwardedHeaders(
|
|
787
805
|
getFirstForwardedValue(headers.get("x-forwarded-proto") ?? void 0),
|
|
788
806
|
getFirstForwardedValue(headers.get("x-forwarded-host") ?? void 0),
|
|
@@ -815,12 +833,7 @@ class FetchState {
|
|
|
815
833
|
this.clientAddress = forwardedFor;
|
|
816
834
|
}
|
|
817
835
|
}
|
|
818
|
-
|
|
819
|
-
this.request = new Request(this.url, oldRequest);
|
|
820
|
-
const app = Reflect.get(oldRequest, appSymbol);
|
|
821
|
-
if (app !== void 0) {
|
|
822
|
-
Reflect.set(this.request, appSymbol, app);
|
|
823
|
-
}
|
|
836
|
+
this.request = new Request(this.url, this.request);
|
|
824
837
|
}
|
|
825
838
|
/**
|
|
826
839
|
* Returns the resolved `props` for this render, computing them lazily
|
|
@@ -834,17 +847,16 @@ class FetchState {
|
|
|
834
847
|
this.props = this.initialProps;
|
|
835
848
|
return this.props;
|
|
836
849
|
}
|
|
837
|
-
const pipeline = this.pipeline;
|
|
838
850
|
const mod = await this.loadComponentInstance();
|
|
839
851
|
this.props = await getProps({
|
|
840
852
|
mod,
|
|
841
853
|
routeData: this.routeData,
|
|
842
|
-
routeCache:
|
|
854
|
+
routeCache: getRouteCache(this.manifest),
|
|
843
855
|
pathname: this.pathname,
|
|
844
|
-
logger:
|
|
845
|
-
serverLike:
|
|
846
|
-
base:
|
|
847
|
-
trailingSlash:
|
|
856
|
+
logger: this.logger,
|
|
857
|
+
serverLike: this.manifest.serverLike,
|
|
858
|
+
base: this.manifest.base,
|
|
859
|
+
trailingSlash: this.manifest.trailingSlash
|
|
848
860
|
});
|
|
849
861
|
return this.props;
|
|
850
862
|
}
|
|
@@ -884,7 +896,7 @@ class FetchState {
|
|
|
884
896
|
return state.computePreferredLocaleList();
|
|
885
897
|
},
|
|
886
898
|
request: this.request,
|
|
887
|
-
site: this.
|
|
899
|
+
site: getSite(this.manifest),
|
|
888
900
|
url: this.url,
|
|
889
901
|
get originPathname() {
|
|
890
902
|
return getOriginPathname(state.request);
|
|
@@ -895,13 +907,13 @@ class FetchState {
|
|
|
895
907
|
get logger() {
|
|
896
908
|
return {
|
|
897
909
|
info(msg) {
|
|
898
|
-
state.
|
|
910
|
+
state.logger.info(null, msg);
|
|
899
911
|
},
|
|
900
912
|
warn(msg) {
|
|
901
|
-
state.
|
|
913
|
+
state.logger.warn(null, msg);
|
|
902
914
|
},
|
|
903
915
|
error(msg) {
|
|
904
|
-
state.
|
|
916
|
+
state.logger.error(null, msg);
|
|
905
917
|
}
|
|
906
918
|
};
|
|
907
919
|
}
|
|
@@ -925,7 +937,6 @@ class FetchState {
|
|
|
925
937
|
const rewrite = async (reroutePayload) => {
|
|
926
938
|
return await state.rewrite(reroutePayload);
|
|
927
939
|
};
|
|
928
|
-
Reflect.set(actionApiContext, pipelineSymbol, this.pipeline);
|
|
929
940
|
actionApiContext[fetchStateSymbol] = this;
|
|
930
941
|
this.apiContext = Object.assign(actionApiContext, {
|
|
931
942
|
props: this.props,
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { FetchState as BaseFetchState } from './fetch-state.js';
|
|
2
2
|
import type { AstroFetchState } from './fetch-state.js';
|
|
3
3
|
export type { AstroFetchState };
|
|
4
|
+
/**
|
|
5
|
+
* The public per-request state, constructible from a bare `Request`.
|
|
6
|
+
* Static, build-time data comes from the ambient manifest — the manifest
|
|
7
|
+
* module bundled into every Astro-built server — so no app, pipeline, or
|
|
8
|
+
* request-attached handle is needed.
|
|
9
|
+
*/
|
|
4
10
|
export declare class FetchState extends BaseFetchState {
|
|
5
11
|
constructor(request: Request);
|
|
6
12
|
}
|
|
@@ -52,9 +58,10 @@ export declare function redirects(state: FetchState): Promise<Response> | undefi
|
|
|
52
58
|
*/
|
|
53
59
|
export declare function actions(state: FetchState): Promise<Response | undefined> | undefined;
|
|
54
60
|
/**
|
|
55
|
-
* Post-processes a response against the
|
|
61
|
+
* Post-processes a response against the manifest's i18n configuration.
|
|
56
62
|
* Handles locale redirects, 404s for invalid locales, and fallback
|
|
57
|
-
* routing. Returns the response unmodified if i18n is not configured
|
|
63
|
+
* routing. Returns the response unmodified if i18n is not configured
|
|
64
|
+
* (or the routing strategy is `manual`).
|
|
58
65
|
*/
|
|
59
66
|
export declare function i18n(state: FetchState, response: Response): Promise<Response>;
|
|
60
67
|
/**
|
package/dist/core/fetch/index.js
CHANGED
|
@@ -1,67 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { handleAction } from "../../actions/handler.js";
|
|
2
2
|
import { FetchState as BaseFetchState } from "./fetch-state.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import { handleCache } from "../cache/handler.js";
|
|
4
|
+
import { finalizeI18n, getI18n } from "../i18n/handler.js";
|
|
5
|
+
import { getAmbientManifest } from "../manifest/ambient.js";
|
|
6
|
+
import { handleMiddlewareWithErrorFallback } from "../middleware/astro-middleware.js";
|
|
7
|
+
import { handlePagesWithErrorFallback } from "../pages/handler.js";
|
|
8
8
|
import { renderRedirect } from "../redirects/render.js";
|
|
9
|
-
import {
|
|
9
|
+
import { handleRequest } from "../routing/handler.js";
|
|
10
10
|
import { provideSession } from "../session/provider.js";
|
|
11
|
-
import {
|
|
12
|
-
function getApp(request) {
|
|
13
|
-
const app = Reflect.get(request, appSymbol);
|
|
14
|
-
if (!app) {
|
|
15
|
-
throw new Error(
|
|
16
|
-
"FetchState(request) called on a request without an attached app. Ensure it runs inside Astro's request pipeline."
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
return app;
|
|
20
|
-
}
|
|
11
|
+
import { handleTrailingSlash } from "../routing/trailing-slash-handler.js";
|
|
21
12
|
class FetchState extends BaseFetchState {
|
|
22
13
|
constructor(request) {
|
|
23
|
-
super(
|
|
14
|
+
super(getAmbientManifest(), request);
|
|
24
15
|
}
|
|
25
16
|
}
|
|
26
|
-
const astroHandlers = /* @__PURE__ */ new WeakMap();
|
|
27
17
|
function astro(state) {
|
|
28
|
-
|
|
29
|
-
let handler = astroHandlers.get(app);
|
|
30
|
-
if (!handler) {
|
|
31
|
-
handler = new AstroHandler(app);
|
|
32
|
-
astroHandlers.set(app, handler);
|
|
33
|
-
}
|
|
34
|
-
return handler.handle(state);
|
|
18
|
+
return handleRequest(state);
|
|
35
19
|
}
|
|
36
|
-
const trailingSlashHandlers = /* @__PURE__ */ new WeakMap();
|
|
37
20
|
function trailingSlash(state) {
|
|
38
|
-
|
|
39
|
-
let handler = trailingSlashHandlers.get(app);
|
|
40
|
-
if (!handler) {
|
|
41
|
-
handler = new TrailingSlashHandler(app);
|
|
42
|
-
trailingSlashHandlers.set(app, handler);
|
|
43
|
-
}
|
|
44
|
-
return handler.handle(state);
|
|
21
|
+
return handleTrailingSlash(state);
|
|
45
22
|
}
|
|
46
|
-
const middlewareInstances = /* @__PURE__ */ new WeakMap();
|
|
47
23
|
function middleware(state, next) {
|
|
48
|
-
|
|
49
|
-
let mw = middlewareInstances.get(app);
|
|
50
|
-
if (!mw) {
|
|
51
|
-
mw = new AstroMiddleware(app.pipeline);
|
|
52
|
-
middlewareInstances.set(app, mw);
|
|
53
|
-
}
|
|
54
|
-
return mw.handleWithErrorFallback(app, state, (s, _ctx) => next(s));
|
|
24
|
+
return handleMiddlewareWithErrorFallback(state, (s, _ctx) => next(s));
|
|
55
25
|
}
|
|
56
|
-
const pagesHandlers = /* @__PURE__ */ new WeakMap();
|
|
57
26
|
function pages(state) {
|
|
58
|
-
|
|
59
|
-
let handler = pagesHandlers.get(app);
|
|
60
|
-
if (!handler) {
|
|
61
|
-
handler = new PagesHandler(app.pipeline);
|
|
62
|
-
pagesHandlers.set(app, handler);
|
|
63
|
-
}
|
|
64
|
-
return handler.handleWithErrorFallback(app, state);
|
|
27
|
+
return handlePagesWithErrorFallback(state);
|
|
65
28
|
}
|
|
66
29
|
function sessions(state) {
|
|
67
30
|
return provideSession(state);
|
|
@@ -72,40 +35,16 @@ function redirects(state) {
|
|
|
72
35
|
}
|
|
73
36
|
return void 0;
|
|
74
37
|
}
|
|
75
|
-
const actionHandlers = /* @__PURE__ */ new WeakMap();
|
|
76
38
|
function actions(state) {
|
|
77
|
-
|
|
78
|
-
let handler = actionHandlers.get(app);
|
|
79
|
-
if (!handler) {
|
|
80
|
-
handler = new ActionHandler();
|
|
81
|
-
actionHandlers.set(app, handler);
|
|
82
|
-
}
|
|
83
|
-
return handler.handle(state.getAPIContext(), state);
|
|
84
|
-
}
|
|
85
|
-
const i18nHandlers = /* @__PURE__ */ new WeakMap();
|
|
86
|
-
function getI18n(app) {
|
|
87
|
-
let handler = i18nHandlers.get(app);
|
|
88
|
-
if (handler === void 0) {
|
|
89
|
-
const config = app.manifest.i18n;
|
|
90
|
-
handler = config && config.strategy !== "manual" ? new I18n(config, app.manifest.base, app.manifest.trailingSlash, app.manifest.buildFormat) : null;
|
|
91
|
-
i18nHandlers.set(app, handler);
|
|
92
|
-
}
|
|
93
|
-
return handler;
|
|
39
|
+
return handleAction(state.getAPIContext(), state);
|
|
94
40
|
}
|
|
95
41
|
function i18n(state, response) {
|
|
96
|
-
const
|
|
97
|
-
if (!
|
|
98
|
-
return
|
|
42
|
+
const compiled = getI18n(state.manifest);
|
|
43
|
+
if (!compiled) return Promise.resolve(response);
|
|
44
|
+
return finalizeI18n(compiled, state, response);
|
|
99
45
|
}
|
|
100
|
-
const cacheHandlers = /* @__PURE__ */ new WeakMap();
|
|
101
46
|
function cache(state, next) {
|
|
102
|
-
|
|
103
|
-
let handler = cacheHandlers.get(app);
|
|
104
|
-
if (!handler) {
|
|
105
|
-
handler = new CacheHandler(app);
|
|
106
|
-
cacheHandlers.set(app, handler);
|
|
107
|
-
}
|
|
108
|
-
return handler.handle(state, next);
|
|
47
|
+
return handleCache(state, next);
|
|
109
48
|
}
|
|
110
49
|
export {
|
|
111
50
|
FetchState,
|
|
@@ -63,7 +63,8 @@ function vitePluginFetchable({ settings }) {
|
|
|
63
63
|
}
|
|
64
64
|
return {
|
|
65
65
|
code: `import { DefaultFetchHandler } from 'astro/app/fetch/default-handler';
|
|
66
|
-
export default new DefaultFetchHandler()
|
|
66
|
+
export default new DefaultFetchHandler();
|
|
67
|
+
export const isDefaultFetchHandler = true;`
|
|
67
68
|
};
|
|
68
69
|
}
|
|
69
70
|
}
|
|
@@ -1,18 +1,33 @@
|
|
|
1
|
+
import { I18nRouter } from '../../i18n/router.js';
|
|
1
2
|
import type { SSRManifest } from '../app/types.js';
|
|
2
3
|
import type { FetchState } from '../fetch/fetch-state.js';
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* so it runs as an explicit step in `AstroHandler.render` after the
|
|
8
|
-
* middleware chain returns.
|
|
9
|
-
*
|
|
10
|
-
* Public entry points in `astro:i18n` (`createMiddleware`) preserve the
|
|
11
|
-
* middleware-shaped API by wrapping an `I18n` instance in a
|
|
12
|
-
* `MiddlewareHandler` closure.
|
|
5
|
+
* The compiled i18n configuration for a manifest: the config values plus the
|
|
6
|
+
* `I18nRouter` (with its inverted domain lookup table), compiled once and
|
|
7
|
+
* reused across requests.
|
|
13
8
|
*/
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
export interface CompiledI18n {
|
|
10
|
+
config: NonNullable<SSRManifest['i18n']>;
|
|
11
|
+
base: SSRManifest['base'];
|
|
12
|
+
trailingSlash: SSRManifest['trailingSlash'];
|
|
13
|
+
format: SSRManifest['buildFormat'];
|
|
14
|
+
router: I18nRouter;
|
|
18
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Pure compile from explicit values — used by `astro:i18n`'s manual-mode
|
|
18
|
+
* middleware wrapper (`src/i18n/middleware.ts`), which receives the values as
|
|
19
|
+
* arguments rather than reading a manifest.
|
|
20
|
+
*/
|
|
21
|
+
export declare function compileI18n(i18n: NonNullable<SSRManifest['i18n']>, base: SSRManifest['base'], trailingSlash: SSRManifest['trailingSlash'], format: SSRManifest['buildFormat']): CompiledI18n;
|
|
22
|
+
/**
|
|
23
|
+
* The compiled i18n post-processor for a manifest, or `null` when i18n is
|
|
24
|
+
* unset or the routing strategy is `manual`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getI18n(manifest: SSRManifest): CompiledI18n | null;
|
|
27
|
+
/**
|
|
28
|
+
* Post-processes a rendered `Response` against the compiled i18n
|
|
29
|
+
* configuration, as an explicit step in `handleRequest` after the middleware
|
|
30
|
+
* chain returns. The manual-strategy public API (`astro:i18n.middleware(...)`)
|
|
31
|
+
* wraps this in a middleware-shaped closure.
|
|
32
|
+
*/
|
|
33
|
+
export declare function finalizeI18n(compiled: CompiledI18n, state: FetchState, response: Response): Promise<Response>;
|