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.
Files changed (151) hide show
  1. package/dist/actions/handler.d.ts +6 -12
  2. package/dist/actions/handler.js +30 -40
  3. package/dist/actions/load.d.ts +12 -0
  4. package/dist/actions/load.js +55 -0
  5. package/dist/actions/runtime/entrypoints/server.js +5 -4
  6. package/dist/actions/runtime/server.js +8 -6
  7. package/dist/assets/fonts/providers/index.d.ts +1 -1
  8. package/dist/assets/fonts/providers/index.js +2 -12
  9. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  10. package/dist/container/environment.d.ts +20 -0
  11. package/dist/container/environment.js +106 -0
  12. package/dist/container/index.js +65 -32
  13. package/dist/content/content-layer.js +3 -3
  14. package/dist/content/data-store-writer.d.ts +7 -10
  15. package/dist/content/data-store-writer.js +62 -27
  16. package/dist/content/data-store.d.ts +20 -3
  17. package/dist/content/data-store.js +28 -7
  18. package/dist/content/mutable-data-store.js +15 -10
  19. package/dist/content/runtime.d.ts +3 -2
  20. package/dist/content/runtime.js +43 -26
  21. package/dist/core/app/app.d.ts +0 -2
  22. package/dist/core/app/app.js +0 -7
  23. package/dist/core/app/base.d.ts +32 -20
  24. package/dist/core/app/base.js +76 -66
  25. package/dist/core/app/dev-facade.d.ts +27 -0
  26. package/dist/core/app/dev-facade.js +51 -0
  27. package/dist/core/app/entrypoints/index.d.ts +0 -1
  28. package/dist/core/app/entrypoints/index.js +0 -2
  29. package/dist/core/app/entrypoints/virtual/dev.js +24 -19
  30. package/dist/core/app/node.js +13 -14
  31. package/dist/core/app/prepare-response.d.ts +1 -1
  32. package/dist/core/app/validate-headers.js +7 -3
  33. package/dist/core/build/app.d.ts +31 -6
  34. package/dist/core/build/app.js +31 -13
  35. package/dist/core/build/environment.d.ts +25 -0
  36. package/dist/core/build/environment.js +157 -0
  37. package/dist/core/cache/handler.d.ts +13 -7
  38. package/dist/core/cache/handler.js +55 -51
  39. package/dist/core/cache/provider.d.ts +4 -0
  40. package/dist/core/cache/provider.js +15 -0
  41. package/dist/core/constants.d.ts +0 -11
  42. package/dist/core/constants.js +1 -5
  43. package/dist/core/dev/dev.js +1 -1
  44. package/dist/core/environment/dev-nonrunnable.d.ts +6 -0
  45. package/dist/core/environment/dev-nonrunnable.js +170 -0
  46. package/dist/core/environment/index.d.ts +90 -0
  47. package/dist/core/environment/index.js +12 -0
  48. package/dist/core/environment/production.d.ts +6 -0
  49. package/dist/core/environment/production.js +117 -0
  50. package/dist/core/errors/build-handler.d.ts +5 -10
  51. package/dist/core/errors/build-handler.js +11 -17
  52. package/dist/core/errors/default-handler.d.ts +4 -9
  53. package/dist/core/errors/default-handler.js +92 -107
  54. package/dist/core/errors/dev-handler.d.ts +7 -11
  55. package/dist/core/errors/dev-handler.js +71 -69
  56. package/dist/core/errors/errors-data.d.ts +18 -0
  57. package/dist/core/errors/errors-data.js +7 -0
  58. package/dist/core/errors/handler.d.ts +22 -3
  59. package/dist/core/errors/handler.js +25 -0
  60. package/dist/core/fetch/default-handler.d.ts +15 -8
  61. package/dist/core/fetch/default-handler.js +12 -34
  62. package/dist/core/fetch/features.d.ts +23 -0
  63. package/dist/core/fetch/features.js +27 -0
  64. package/dist/core/fetch/fetch-state.d.ts +52 -7
  65. package/dist/core/fetch/fetch-state.js +92 -81
  66. package/dist/core/fetch/index.d.ts +9 -2
  67. package/dist/core/fetch/index.js +18 -79
  68. package/dist/core/fetch/vite-plugin.js +2 -1
  69. package/dist/core/i18n/handler.d.ts +28 -13
  70. package/dist/core/i18n/handler.js +100 -100
  71. package/dist/core/logger/manifest-logger.d.ts +31 -0
  72. package/dist/core/logger/manifest-logger.js +37 -0
  73. package/dist/core/manifest/ambient-source.d.ts +2 -0
  74. package/dist/core/manifest/ambient-source.js +4 -0
  75. package/dist/core/manifest/ambient.d.ts +16 -0
  76. package/dist/core/manifest/ambient.js +22 -0
  77. package/dist/core/manifest/derived.d.ts +3 -0
  78. package/dist/core/manifest/derived.js +10 -0
  79. package/dist/core/manifest/memo.d.ts +31 -0
  80. package/dist/core/manifest/memo.js +47 -0
  81. package/dist/core/messages/runtime.js +1 -1
  82. package/dist/core/middleware/astro-middleware.d.ts +25 -35
  83. package/dist/core/middleware/astro-middleware.js +61 -81
  84. package/dist/core/middleware/load.d.ts +19 -0
  85. package/dist/core/middleware/load.js +36 -0
  86. package/dist/core/middleware/sequence.js +15 -7
  87. package/dist/core/pages/handler.d.ts +18 -25
  88. package/dist/core/pages/handler.js +68 -84
  89. package/dist/core/redirects/render.js +3 -8
  90. package/dist/core/render/index.d.ts +0 -1
  91. package/dist/core/render/index.js +0 -2
  92. package/dist/core/render/route-cache.d.ts +6 -1
  93. package/dist/core/render/route-cache.js +11 -1
  94. package/dist/core/rewrites/handler.d.ts +4 -6
  95. package/dist/core/rewrites/handler.js +19 -20
  96. package/dist/core/routing/default.d.ts +2 -0
  97. package/dist/core/routing/default.js +7 -1
  98. package/dist/core/routing/dev.d.ts +1 -3
  99. package/dist/core/routing/dev.js +12 -5
  100. package/dist/core/routing/handler.d.ts +6 -16
  101. package/dist/core/routing/handler.js +126 -164
  102. package/dist/core/routing/helpers.d.ts +7 -1
  103. package/dist/core/routing/helpers.js +21 -0
  104. package/dist/core/routing/match-request.d.ts +10 -0
  105. package/dist/core/routing/match-request.js +57 -0
  106. package/dist/core/routing/route-table.d.ts +34 -0
  107. package/dist/core/routing/route-table.js +41 -0
  108. package/dist/core/routing/trailing-slash-handler.d.ts +4 -14
  109. package/dist/core/routing/trailing-slash-handler.js +39 -50
  110. package/dist/core/server-islands/mappings.d.ts +6 -0
  111. package/dist/core/server-islands/mappings.js +12 -0
  112. package/dist/core/session/driver.d.ts +4 -0
  113. package/dist/core/session/driver.js +14 -0
  114. package/dist/core/session/handler.d.ts +1 -1
  115. package/dist/core/session/handler.js +8 -8
  116. package/dist/core/session/provider-disabled.js +2 -2
  117. package/dist/entrypoints/prerender.js +5 -1
  118. package/dist/i18n/middleware.d.ts +4 -4
  119. package/dist/i18n/middleware.js +3 -3
  120. package/dist/manifest/serialized.d.ts +1 -0
  121. package/dist/manifest/serialized.js +9 -2
  122. package/dist/runtime/prerender/static-paths.d.ts +14 -2
  123. package/dist/runtime/prerender/static-paths.js +4 -3
  124. package/dist/types/public/config.d.ts +433 -241
  125. package/dist/vite-plugin-app/createAstroServerApp.js +22 -18
  126. package/dist/vite-plugin-app/environment.d.ts +18 -0
  127. package/dist/vite-plugin-app/environment.js +210 -0
  128. package/dist/vite-plugin-app/handle-request.d.ts +30 -0
  129. package/dist/vite-plugin-app/handle-request.js +129 -0
  130. package/dist/vite-plugin-app/index.d.ts +1 -1
  131. package/dist/vite-plugin-app/index.js +1 -1
  132. package/package.json +14 -7
  133. package/src/core/README.md +37 -0
  134. package/src/core/manifest/ambient-source.ts +9 -0
  135. package/src/types/README.md +5 -0
  136. package/dist/container/pipeline.d.ts +0 -14
  137. package/dist/container/pipeline.js +0 -78
  138. package/dist/core/app/dev/app.d.ts +0 -31
  139. package/dist/core/app/dev/app.js +0 -80
  140. package/dist/core/app/dev/pipeline.d.ts +0 -17
  141. package/dist/core/app/dev/pipeline.js +0 -133
  142. package/dist/core/app/pipeline.d.ts +0 -14
  143. package/dist/core/app/pipeline.js +0 -123
  144. package/dist/core/base-pipeline.d.ts +0 -183
  145. package/dist/core/base-pipeline.js +0 -293
  146. package/dist/core/build/pipeline.d.ts +0 -38
  147. package/dist/core/build/pipeline.js +0 -202
  148. package/dist/vite-plugin-app/app.d.ts +0 -62
  149. package/dist/vite-plugin-app/app.js +0 -237
  150. package/dist/vite-plugin-app/pipeline.d.ts +0 -25
  151. 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 { Rewrites } from "../rewrites/handler.js";
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
- pipeline;
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 `AstroHandler` after routeData is known (in dev, when
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. `AstroHandler` sets this from
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(pipeline, request, options) {
166
- this.pipeline = pipeline;
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
- pipeline.manifest.i18n,
194
- pipeline.manifest.base,
195
- pipeline.manifest.trailingSlash,
196
- pipeline.logger,
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 (pipeline.manifest.allowedDomains && pipeline.manifest.allowedDomains.length > 0 && !this.routeData?.prerender) {
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 Rewrites handler.
245
+ * Triggers a rewrite. Delegates to the rewrites handler module.
225
246
  */
226
247
  rewrite(payload) {
227
- return (this.#rewrites ??= new Rewrites()).execute(this, payload);
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 pipeline = this.pipeline;
234
- const { clientDirectives, inlinedScripts, compressHTML, manifest, renderers, resolve } = pipeline;
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 pipeline.headElements(routeData);
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 pipeline.componentMetadata(routeData) ?? manifest.componentMetadata;
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 pipeline.getServerIslands();
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, pipeline, url } = this;
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: pipeline.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
- pipeline.logger.info(null, msg);
446
+ logger.info(null, msg);
427
447
  },
428
448
  warn(msg) {
429
- pipeline.logger.warn(null, msg);
449
+ logger.warn(null, msg);
430
450
  },
431
451
  error(msg) {
432
- pipeline.logger.error(null, msg);
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 { pipeline, clientAddress } = this;
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 (pipeline.adapterName) {
472
+ if (this.manifest.adapterName) {
453
473
  throw new AstroError({
454
474
  ...AstroErrorData.ClientAddressNotAvailable,
455
- message: AstroErrorData.ClientAddressNotAvailable.message(pipeline.adapterName)
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
- const { pipeline } = this;
466
- if (!pipeline.manifest.csp) {
467
- if (pipeline.runtimeMode === "production") {
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
- pipeline.logger.warn(
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
- pipeline: { i18n },
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
- pipeline: { i18n },
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
- pipeline: { i18n },
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.pipeline.getComponentByRoute(this.routeData).then((mod) => {
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.pipeline.logger.warn(
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 = pipeline.matchRoute(this.pathname);
716
- if (matched && matched.prerender && pipeline.manifest.serverLike) {
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 = pipeline.matchAllRoutes(this.pathname);
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
- pipeline.logger.debug("router", "Astro matched the following route for " + this.request.url);
727
- pipeline.logger.debug("router", "RouteData:\n" + this.routeData);
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(pipeline.manifestData);
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
- pipeline.logger.debug("router", "Astro hasn't found routes that match " + this.request.url);
736
- pipeline.logger.debug("router", "Here's the available routes:\n", pipeline.manifestData);
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 pipeline's base from a normalized request pathname and prepends
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.pipeline.manifest.base;
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.pipeline.logger.error(null, e.toString());
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.pipeline.manifest.allowedDomains;
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
- const oldRequest = this.request;
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: pipeline.routeCache,
854
+ routeCache: getRouteCache(this.manifest),
843
855
  pathname: this.pathname,
844
- logger: pipeline.logger,
845
- serverLike: pipeline.manifest.serverLike,
846
- base: pipeline.manifest.base,
847
- trailingSlash: pipeline.manifest.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.pipeline.site,
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.pipeline.logger.info(null, msg);
910
+ state.logger.info(null, msg);
899
911
  },
900
912
  warn(msg) {
901
- state.pipeline.logger.warn(null, msg);
913
+ state.logger.warn(null, msg);
902
914
  },
903
915
  error(msg) {
904
- state.pipeline.logger.error(null, msg);
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 app's i18n configuration.
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
  /**
@@ -1,67 +1,30 @@
1
- import { ActionHandler } from "../../actions/handler.js";
1
+ import { handleAction } from "../../actions/handler.js";
2
2
  import { FetchState as BaseFetchState } from "./fetch-state.js";
3
- import { CacheHandler } from "../cache/handler.js";
4
- import { appSymbol } from "../constants.js";
5
- import { I18n } from "../i18n/handler.js";
6
- import { AstroMiddleware } from "../middleware/astro-middleware.js";
7
- import { PagesHandler } from "../pages/handler.js";
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 { AstroHandler } from "../routing/handler.js";
9
+ import { handleRequest } from "../routing/handler.js";
10
10
  import { provideSession } from "../session/provider.js";
11
- import { TrailingSlashHandler } from "../routing/trailing-slash-handler.js";
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(getApp(request).pipeline, request);
14
+ super(getAmbientManifest(), request);
24
15
  }
25
16
  }
26
- const astroHandlers = /* @__PURE__ */ new WeakMap();
27
17
  function astro(state) {
28
- const app = getApp(state.request);
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
- const app = getApp(state.request);
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
- const app = getApp(state.request);
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
- const app = getApp(state.request);
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
- const app = getApp(state.request);
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 handler = getI18n(getApp(state.request));
97
- if (!handler) return Promise.resolve(response);
98
- return handler.finalize(state, response);
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
- const app = getApp(state.request);
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
- * Post-processes a rendered `Response` against the app's i18n
5
- * configuration. This is the logic that previously ran as the internal
6
- * `createI18nMiddleware` middleware — lifted out of the middleware layer
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 declare class I18n {
15
- #private;
16
- constructor(i18n: NonNullable<SSRManifest['i18n']>, base: SSRManifest['base'], trailingSlash: SSRManifest['trailingSlash'], format: SSRManifest['buildFormat']);
17
- finalize(state: FetchState, response: Response): Promise<Response>;
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>;