cloudcommerce 2.6.2 → 2.6.4

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 (158) hide show
  1. package/.github/workflows/test-apps.yml +1 -1
  2. package/CHANGELOG.md +21 -0
  3. package/README.md +2 -0
  4. package/ecomplus-stores/barradoce/functions/many/package.json +3 -3
  5. package/ecomplus-stores/barradoce/functions/ssr/content/reviews.json +71 -0
  6. package/ecomplus-stores/barradoce/functions/ssr/content/types.d.ts +5 -0
  7. package/ecomplus-stores/barradoce/functions/ssr/package.json +6 -6
  8. package/ecomplus-stores/barradoce/functions/ssr/src/components/ProductDetails.vue +2 -1
  9. package/ecomplus-stores/barradoce/functions/ssr/src/env.d.ts +1 -0
  10. package/ecomplus-stores/barradoce/functions/with-apps/package.json +3 -3
  11. package/ecomplus-stores/barradoce/package.json +2 -2
  12. package/package.json +7 -7
  13. package/packages/api/package.json +1 -1
  14. package/packages/apps/affiliate-program/package.json +1 -1
  15. package/packages/apps/correios/package.json +1 -1
  16. package/packages/apps/custom-payment/package.json +1 -1
  17. package/packages/apps/custom-shipping/package.json +1 -1
  18. package/packages/apps/datafrete/package.json +1 -1
  19. package/packages/apps/discounts/package.json +1 -1
  20. package/packages/apps/emails/package.json +1 -1
  21. package/packages/apps/fb-conversions/package.json +1 -1
  22. package/packages/apps/flash-courier/package.json +1 -1
  23. package/packages/apps/frenet/package.json +1 -1
  24. package/packages/apps/galaxpay/package.json +1 -1
  25. package/packages/apps/google-analytics/package.json +1 -1
  26. package/packages/apps/jadlog/package.json +1 -1
  27. package/packages/apps/loyalty-points/package.json +1 -1
  28. package/packages/apps/mandae/package.json +1 -1
  29. package/packages/apps/melhor-envio/package.json +1 -1
  30. package/packages/apps/mercadopago/package.json +1 -1
  31. package/packages/apps/pagarme/package.json +2 -2
  32. package/packages/apps/pagarme-v5/package.json +1 -1
  33. package/packages/apps/paghiper/package.json +1 -1
  34. package/packages/apps/pix/package.json +1 -1
  35. package/packages/apps/tiny-erp/package.json +1 -1
  36. package/packages/apps/webhooks/package.json +1 -1
  37. package/packages/cli/package.json +2 -2
  38. package/packages/config/package.json +1 -1
  39. package/packages/emails/package.json +2 -2
  40. package/packages/eslint/package.json +6 -6
  41. package/packages/events/package.json +1 -1
  42. package/packages/feeds/package.json +1 -1
  43. package/packages/firebase/package.json +2 -2
  44. package/packages/i18n/package.json +1 -1
  45. package/packages/modules/package.json +1 -1
  46. package/packages/passport/package.json +1 -1
  47. package/packages/ssr/lib/lib/cron-ssr-save-views.js +71 -66
  48. package/packages/ssr/lib/lib/cron-ssr-save-views.js.map +1 -1
  49. package/packages/ssr/package.json +6 -6
  50. package/packages/ssr/src/lib/cron-ssr-save-views.ts +84 -77
  51. package/packages/storefront/dist/client/_astro/AccountPage.B4WZaOzX.js +1 -0
  52. package/packages/storefront/dist/client/_astro/CartSidebar.DAGdpIcU.js +1 -0
  53. package/packages/storefront/dist/client/_astro/HeroSlider.Dq_9kcdU.js +1 -0
  54. package/packages/storefront/dist/client/_astro/PitchBar.BwLlIs6F.js +1 -0
  55. package/packages/storefront/dist/client/_astro/Prices.BgHTq5id.js +1 -0
  56. package/packages/storefront/dist/client/_astro/ProductDetails.CnYNdPl5.js +7 -0
  57. package/packages/storefront/dist/client/_astro/ProductShelf.kfADQTUO.js +1 -0
  58. package/packages/storefront/dist/client/_astro/SearchModal.DcmvABes.js +1 -0
  59. package/packages/storefront/dist/client/_astro/SearchShowcase.C9GWwOnF.js +1 -0
  60. package/packages/storefront/dist/client/_astro/ShippingCalculator.DE01D7dt.js +1 -0
  61. package/packages/storefront/dist/client/_astro/ShopHeader.Cf4t6O6z.js +7 -0
  62. package/packages/storefront/dist/client/_astro/_commonjsHelpers.Cpj98o6Y.js +1 -0
  63. package/packages/storefront/dist/client/_astro/_plugin-vue_export-helper.CBemkWnU.js +5 -0
  64. package/packages/storefront/dist/client/_astro/{_slug_.4W7qhV-L.css → _slug_.DX_OkMX7.css} +1 -1
  65. package/packages/storefront/dist/client/_astro/{afetch.OifQZgwR.js → afetch.DPLba2tr.js} +1 -1
  66. package/packages/storefront/dist/client/_astro/client.CdXC84C5.js +1 -0
  67. package/packages/storefront/dist/client/_astro/customer-session.CNe1heRH.js +7 -0
  68. package/packages/storefront/dist/client/_astro/{firebase-app.iLdzDVjL.js → firebase-app.CBckq0Sj.js} +1 -1
  69. package/packages/storefront/dist/client/_astro/{format-money.1_HtF5S2.js → format-money.DINpWB0x.js} +1 -1
  70. package/packages/storefront/dist/client/_astro/grid-title.D4m7-g3h.js +1 -0
  71. package/packages/storefront/dist/client/_astro/hoisted.B2rH1xwX.js +8 -0
  72. package/packages/storefront/dist/client/_astro/hoisted.DBPXHTEb.js +1 -0
  73. package/packages/storefront/dist/client/_astro/hoisted.EBqhuD5o.js +1 -0
  74. package/packages/storefront/dist/client/_astro/{hoisted.GaT7bmE3.js → hoisted.ut_nNM_H.js} +1 -1
  75. package/packages/storefront/dist/client/_astro/i18n.B3skIOFg.js +1 -0
  76. package/packages/storefront/dist/client/_astro/img-sizes.rFK7so02.js +1 -0
  77. package/packages/storefront/dist/client/_astro/img.D5a6GzeE.js +1 -0
  78. package/packages/storefront/dist/client/_astro/index.CFw6O-Kt.js +1 -0
  79. package/packages/storefront/dist/client/_astro/index.DBfgCyd-.js +1 -0
  80. package/packages/storefront/dist/client/_astro/{modules-info.HP6478mG.js → modules-info.BHKiT6oA.js} +1 -1
  81. package/packages/storefront/dist/client/_astro/name.BZA9xqh-.js +1 -0
  82. package/packages/storefront/dist/client/_astro/photoswipe.esm.C0FT-EY-.js +4 -0
  83. package/packages/storefront/dist/client/_astro/price.CHiL6Z1J.js +1 -0
  84. package/packages/storefront/dist/client/_astro/sf-utils.Cigv01cN.js +13 -0
  85. package/packages/storefront/dist/client/_astro/shopping-cart.D-w8Z-4p.js +1 -0
  86. package/packages/storefront/dist/client/_astro/use-analytics.CQDdNgwF.js +1 -0
  87. package/packages/storefront/dist/client/_astro/use-cms-preview.4Hq7LCmA.js +1 -0
  88. package/packages/storefront/dist/client/_astro/use-product-card.CQRlRsNX.js +1 -0
  89. package/packages/storefront/dist/client/_astro/use-text-value.UjCYLWjm.js +4 -0
  90. package/packages/storefront/dist/client/img/uploads/logo.png +0 -0
  91. package/packages/storefront/dist/server/chunks/{CartSidebar_3_1aFp67.mjs → CartSidebar_BmwcZuxv.mjs} +36 -4
  92. package/packages/storefront/dist/server/chunks/{SearchModal_2azP1u7P.mjs → SearchModal_BvEnUvAx.mjs} +4 -3
  93. package/packages/storefront/dist/server/chunks/_.._DORZHe_Z.mjs +5 -0
  94. package/packages/storefront/dist/server/chunks/{_page__qqIVxbal.mjs → _page__DU3kNewy.mjs} +1 -1
  95. package/packages/storefront/dist/server/chunks/{account_vK6pmJlz.mjs → account_CaTloREf.mjs} +1 -1
  96. package/packages/storefront/dist/server/chunks/astro/{assets-service_631fRtTy.mjs → assets-service_B77Hm2ue.mjs} +2 -2
  97. package/packages/storefront/dist/server/chunks/{astro_u-oSb215.mjs → astro_ISB6VLqs.mjs} +178 -59
  98. package/packages/storefront/dist/server/chunks/index_BTDpenpc.mjs +5 -0
  99. package/packages/storefront/dist/server/chunks/index_D0q4ab_n.mjs +5 -0
  100. package/packages/storefront/dist/server/chunks/{node_zqXXqc-u.mjs → node_C7sdLKL4.mjs} +1 -1
  101. package/packages/storefront/dist/server/chunks/pages/{__ZucPYaOo.mjs → __B4CsSrck.mjs} +1751 -344
  102. package/packages/storefront/dist/server/chunks/pages/{_page__0sN9U0SD.mjs → _page__sb5Idhgp.mjs} +2 -3
  103. package/packages/storefront/dist/server/chunks/pages/{account_OQr_6KN1.mjs → account_iWjHfkwu.mjs} +2 -3
  104. package/packages/storefront/dist/server/chunks/pages/{index_3IjgOEIq.mjs → index_BZlpKBRL.mjs} +41 -4
  105. package/packages/storefront/dist/server/chunks/pages/node_GFu-CQ19.mjs +852 -0
  106. package/packages/storefront/dist/server/chunks/pages/{~fallback_133FK-CP.mjs → ~fallback_C07rzeay.mjs} +2 -3
  107. package/packages/storefront/dist/server/chunks/{index__05fnqFh.mjs → ~fallback_YpJa9BIL.mjs} +1 -1
  108. package/packages/storefront/dist/server/entry.mjs +751 -912
  109. package/packages/storefront/dist/server/manifest_KFjAaJaC.mjs +201 -0
  110. package/packages/storefront/dist/server/renderers.mjs +1 -1
  111. package/packages/storefront/package.json +8 -8
  112. package/packages/storefront/src/lib/composables/use-breadcrumbs.ts +2 -1
  113. package/packages/storefront/src/lib/composables/use-search-showcase.ts +2 -1
  114. package/packages/storefront/src/lib/content.d.ts +4 -1
  115. package/packages/storefront/src/lib/custom-content.d.ts +9 -0
  116. package/packages/storefront/src/lib/ssr-context.ts +6 -4
  117. package/packages/test-base/package.json +1 -1
  118. package/packages/types/package.json +1 -1
  119. package/packages/storefront/dist/client/_astro/AccountPage.0M6_FdU6.js +0 -1
  120. package/packages/storefront/dist/client/_astro/CartSidebar.L0Vbhsdt.js +0 -1
  121. package/packages/storefront/dist/client/_astro/HeroSlider.ju9TsLrJ.js +0 -1
  122. package/packages/storefront/dist/client/_astro/PitchBar.yqD9ycx5.js +0 -1
  123. package/packages/storefront/dist/client/_astro/Prices.xI1rdM1e.js +0 -1
  124. package/packages/storefront/dist/client/_astro/ProductDetails.FQtM5kpd.js +0 -7
  125. package/packages/storefront/dist/client/_astro/ProductShelf.-4fsYkPB.js +0 -1
  126. package/packages/storefront/dist/client/_astro/ProductShelf.GAAhKdTN.js +0 -1
  127. package/packages/storefront/dist/client/_astro/QuantitySelector.v7L8EYOR.js +0 -1
  128. package/packages/storefront/dist/client/_astro/SearchModal.rasg5jV6.js +0 -1
  129. package/packages/storefront/dist/client/_astro/SearchShowcase.kA6jICYo.js +0 -1
  130. package/packages/storefront/dist/client/_astro/ShopHeader.v_L96Y90.js +0 -7
  131. package/packages/storefront/dist/client/_astro/_plugin-vue_export-helper.xATGHWd9.js +0 -5
  132. package/packages/storefront/dist/client/_astro/client.YJ00ta5M.js +0 -1
  133. package/packages/storefront/dist/client/_astro/customer-session.ZD6tLDQJ.js +0 -7
  134. package/packages/storefront/dist/client/_astro/grid-title.pK2Nn3i-.js +0 -1
  135. package/packages/storefront/dist/client/_astro/hoisted.ICXGWNEA.js +0 -1
  136. package/packages/storefront/dist/client/_astro/hoisted.XOXTrHqn.js +0 -1
  137. package/packages/storefront/dist/client/_astro/i18n.zhlBzJt8.js +0 -1
  138. package/packages/storefront/dist/client/_astro/img-sizes.gxAI9JNh.js +0 -1
  139. package/packages/storefront/dist/client/_astro/img.AnjeGdy_.js +0 -1
  140. package/packages/storefront/dist/client/_astro/index.KfrHdfOH.js +0 -1
  141. package/packages/storefront/dist/client/_astro/index.ShNlAyu1.js +0 -1
  142. package/packages/storefront/dist/client/_astro/name.VA3MEpe0.js +0 -1
  143. package/packages/storefront/dist/client/_astro/photoswipe.esm.Ylh9TGkz.js +0 -4
  144. package/packages/storefront/dist/client/_astro/price.Easct8WC.js +0 -1
  145. package/packages/storefront/dist/client/_astro/sf-utils.c42cbZ9W.js +0 -13
  146. package/packages/storefront/dist/client/_astro/shopping-cart.nSNNOrp9.js +0 -1
  147. package/packages/storefront/dist/client/_astro/use-analytics.wTmoP8B1.js +0 -1
  148. package/packages/storefront/dist/client/_astro/use-product-card.UFr8SCuD.js +0 -1
  149. package/packages/storefront/dist/client/_astro/use-text-value.lKqoIagH.js +0 -4
  150. package/packages/storefront/dist/server/chunks/_.._19fCuQdO.mjs +0 -5
  151. package/packages/storefront/dist/server/chunks/pages/node_OmjWRf8D.mjs +0 -112
  152. package/packages/storefront/dist/server/chunks/~fallback_Wahcp9Wk.mjs +0 -5
  153. package/packages/storefront/dist/server/manifest_9FASPYUE.mjs +0 -202
  154. /package/packages/storefront/dist/client/_astro/{index-bea2a320.eWykogwr.js → index-bea2a320.CHELEM8n.js} +0 -0
  155. /package/packages/storefront/dist/client/_astro/{photoswipe-lightbox.esm.dZBqKD9u.js → photoswipe-lightbox.esm.BbYxSZIB.js} +0 -0
  156. /package/packages/storefront/dist/client/_astro/{photoswipe.0V7m2jWu.js → photoswipe.CNpEZKfy.js} +0 -0
  157. /package/packages/storefront/dist/client/_astro/{server-data.4C60Esyt.js → server-data.CUHTES8a.js} +0 -0
  158. /package/packages/storefront/dist/server/chunks/{photoswipe_IcWDJiwc.mjs → photoswipe_wusPJBJF.mjs} +0 -0
@@ -1,244 +1,26 @@
1
1
  import { renderers } from './renderers.mjs';
2
- import { l as levels, g as getEventPrefix, L as Logger, A as AstroIntegrationLogger, manifest } from './manifest_9FASPYUE.mjs';
3
- import fs from 'node:fs';
4
- import { appendForwardSlash as appendForwardSlash$1, joinPaths, trimSlashes, slash, prependForwardSlash as prependForwardSlash$1, removeTrailingForwardSlash, collapseDuplicateSlashes } from '@astrojs/internal-helpers/path';
5
- import { R as ROUTE_DATA_SYMBOL, A as AstroError, o as ResponseSentError, p as MiddlewareNoDataOrNextCalled, q as MiddlewareNotAResponse, G as GetStaticPathsRequired, t as InvalidGetStaticPathsReturn, v as InvalidGetStaticPathsEntry, w as GetStaticPathsExpectedParams, x as GetStaticPathsInvalidRouteParam, P as PageNumberParamNotFound, N as NoMatchingStaticPathFound, y as PrerenderDynamicEndpointPathCollide, z as LocalsNotAnObject, B as ASTRO_VERSION, C as ClientAddressNotAvailable, S as StaticClientAddressNotAvailable, D as renderEndpoint, H as ReservedSlotName, k as renderSlotToString, J as renderJSX, K as chunkToString, O as CantRenderPage, Q as renderPage$1, T as REROUTE_DIRECTIVE_HEADER } from './chunks/astro_u-oSb215.mjs';
2
+ import { l as levels, g as getEventPrefix, L as Logger, A as AstroIntegrationLogger, manifest } from './manifest_KFjAaJaC.mjs';
6
3
  import { serialize, parse } from 'cookie';
4
+ import { A as AstroError, R as ResponseSentError, G as GetStaticPathsRequired, p as InvalidGetStaticPathsReturn, q as InvalidGetStaticPathsEntry, t as GetStaticPathsExpectedParams, v as GetStaticPathsInvalidRouteParam, P as PageNumberParamNotFound, w as ROUTE_TYPE_HEADER, x as MiddlewareNoDataOrNextCalled, y as MiddlewareNotAResponse, N as NoMatchingStaticPathFound, z as PrerenderDynamicEndpointPathCollide, B as ReservedSlotName, k as renderSlotToString, C as renderJSX, D as chunkToString, H as clientAddressSymbol$1, J as ClientAddressNotAvailable, S as StaticClientAddressNotAvailable, K as responseSentSymbol$1, O as LocalsNotAnObject, Q as clientLocalsSymbol, T as ASTRO_VERSION, V as renderEndpoint, W as renderPage, X as REROUTABLE_STATUS_CODES, Y as REROUTE_DIRECTIVE_HEADER } from './chunks/astro_ISB6VLqs.mjs';
5
+ import { joinPaths, slash, prependForwardSlash as prependForwardSlash$1, trimSlashes, appendForwardSlash as appendForwardSlash$1, removeTrailingForwardSlash, collapseDuplicateSlashes } from '@astrojs/internal-helpers/path';
7
6
  import 'kleur/colors';
8
7
  import 'clsx';
9
- import 'cssesc';
10
- import buffer from 'node:buffer';
11
- import crypto from 'node:crypto';
12
8
  import http from 'node:http';
13
9
  import https$1 from 'https';
10
+ import fs from 'node:fs';
14
11
  import enableDestroy from 'server-destroy';
15
12
  import path from 'node:path';
16
13
  import url from 'node:url';
17
14
  import send from 'send';
18
15
  import os from 'node:os';
19
16
  import https from 'node:https';
17
+ import buffer from 'node:buffer';
18
+ import crypto from 'node:crypto';
20
19
  import { onRequest } from './_noop-middleware.mjs';
21
20
 
22
- function shouldAppendForwardSlash(trailingSlash, buildFormat) {
23
- switch (trailingSlash) {
24
- case "always":
25
- return true;
26
- case "never":
27
- return false;
28
- case "ignore": {
29
- switch (buildFormat) {
30
- case "directory":
31
- return true;
32
- case "preserve":
33
- case "file":
34
- return false;
35
- }
36
- }
37
- }
38
- }
39
-
40
- function getPathByLocale(locale, locales) {
41
- for (const loopLocale of locales) {
42
- if (typeof loopLocale === "string") {
43
- if (loopLocale === locale) {
44
- return loopLocale;
45
- }
46
- } else {
47
- for (const code of loopLocale.codes) {
48
- if (code === locale) {
49
- return loopLocale.path;
50
- }
51
- }
52
- }
53
- }
54
- throw new Unreachable();
55
- }
56
- function normalizeTheLocale(locale) {
57
- return locale.replaceAll("_", "-").toLowerCase();
58
- }
59
- function toCodes(locales) {
60
- const codes = [];
61
- for (const locale of locales) {
62
- if (typeof locale === "string") {
63
- codes.push(locale);
64
- } else {
65
- for (const code of locale.codes) {
66
- codes.push(code);
67
- }
68
- }
69
- }
70
- return codes;
71
- }
72
- class Unreachable extends Error {
73
- constructor() {
74
- super(
75
- "Astro encountered an unexpected line of code.\nIn most cases, this is not your fault, but a bug in astro code.\nIf there isn't one already, please create an issue.\nhttps://astro.build/issues"
76
- );
77
- }
78
- }
79
-
80
- const routeDataSymbol$1 = Symbol.for(ROUTE_DATA_SYMBOL);
81
- function pathnameHasLocale(pathname, locales) {
82
- const segments = pathname.split("/");
83
- for (const segment of segments) {
84
- for (const locale of locales) {
85
- if (typeof locale === "string") {
86
- if (normalizeTheLocale(segment) === normalizeTheLocale(locale)) {
87
- return true;
88
- }
89
- } else if (segment === locale.path) {
90
- return true;
91
- }
92
- }
93
- }
94
- return false;
95
- }
96
- function createI18nMiddleware(i18n, base, trailingSlash, buildFormat) {
97
- if (!i18n)
98
- return (_, next) => next();
99
- const prefixAlways = (url, response, context) => {
100
- if (url.pathname === base + "/" || url.pathname === base) {
101
- if (shouldAppendForwardSlash(trailingSlash, buildFormat)) {
102
- return context.redirect(`${appendForwardSlash$1(joinPaths(base, i18n.defaultLocale))}`);
103
- } else {
104
- return context.redirect(`${joinPaths(base, i18n.defaultLocale)}`);
105
- }
106
- } else if (!pathnameHasLocale(url.pathname, i18n.locales)) {
107
- return new Response(null, {
108
- status: 404,
109
- headers: response.headers
110
- });
111
- }
112
- return void 0;
113
- };
114
- const prefixOtherLocales = (url, response) => {
115
- const pathnameContainsDefaultLocale = url.pathname.includes(`/${i18n.defaultLocale}`);
116
- if (pathnameContainsDefaultLocale) {
117
- const newLocation = url.pathname.replace(`/${i18n.defaultLocale}`, "");
118
- response.headers.set("Location", newLocation);
119
- return new Response(null, {
120
- status: 404,
121
- headers: response.headers
122
- });
123
- }
124
- return void 0;
125
- };
126
- const prefixAlwaysNoRedirect = (url, response) => {
127
- const isRoot = url.pathname === base + "/" || url.pathname === base;
128
- if (!(isRoot || pathnameHasLocale(url.pathname, i18n.locales))) {
129
- return new Response(null, {
130
- status: 404,
131
- headers: response.headers
132
- });
133
- }
134
- return void 0;
135
- };
136
- return async (context, next) => {
137
- const routeData = Reflect.get(context.request, routeDataSymbol$1);
138
- if (routeData?.type !== "page" && routeData?.type !== "fallback") {
139
- return await next();
140
- }
141
- const currentLocale = context.currentLocale;
142
- const url = context.url;
143
- const { locales, defaultLocale, fallback, routing } = i18n;
144
- const response = await next();
145
- if (response instanceof Response) {
146
- switch (i18n.routing) {
147
- case "domains-prefix-other-locales": {
148
- if (localeHasntDomain(i18n, currentLocale)) {
149
- const result = prefixOtherLocales(url, response);
150
- if (result) {
151
- return result;
152
- }
153
- }
154
- break;
155
- }
156
- case "pathname-prefix-other-locales": {
157
- const result = prefixOtherLocales(url, response);
158
- if (result) {
159
- return result;
160
- }
161
- break;
162
- }
163
- case "domains-prefix-other-no-redirect": {
164
- if (localeHasntDomain(i18n, currentLocale)) {
165
- const result = prefixAlwaysNoRedirect(url, response);
166
- if (result) {
167
- return result;
168
- }
169
- }
170
- break;
171
- }
172
- case "pathname-prefix-always-no-redirect": {
173
- const result = prefixAlwaysNoRedirect(url, response);
174
- if (result) {
175
- return result;
176
- }
177
- break;
178
- }
179
- case "pathname-prefix-always": {
180
- const result = prefixAlways(url, response, context);
181
- if (result) {
182
- return result;
183
- }
184
- break;
185
- }
186
- case "domains-prefix-always": {
187
- if (localeHasntDomain(i18n, currentLocale)) {
188
- const result = prefixAlways(url, response, context);
189
- if (result) {
190
- return result;
191
- }
192
- }
193
- break;
194
- }
195
- }
196
- if (response.status >= 300 && fallback) {
197
- const fallbackKeys = i18n.fallback ? Object.keys(i18n.fallback) : [];
198
- const segments = url.pathname.split("/");
199
- const urlLocale = segments.find((segment) => {
200
- for (const locale of locales) {
201
- if (typeof locale === "string") {
202
- if (locale === segment) {
203
- return true;
204
- }
205
- } else if (locale.path === segment) {
206
- return true;
207
- }
208
- }
209
- return false;
210
- });
211
- if (urlLocale && fallbackKeys.includes(urlLocale)) {
212
- const fallbackLocale = fallback[urlLocale];
213
- const pathFallbackLocale = getPathByLocale(fallbackLocale, locales);
214
- let newPathname;
215
- if (pathFallbackLocale === defaultLocale && routing === "pathname-prefix-other-locales") {
216
- newPathname = url.pathname.replace(`/${urlLocale}`, ``);
217
- } else {
218
- newPathname = url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`);
219
- }
220
- return context.redirect(newPathname);
221
- }
222
- }
223
- }
224
- return response;
225
- };
226
- }
227
- const i18nPipelineHook = (ctx) => {
228
- Reflect.set(ctx.request, routeDataSymbol$1, ctx.route);
229
- };
230
- function localeHasntDomain(i18n, currentLocale) {
231
- for (const domainLocale of Object.values(i18n.domainLookupTable)) {
232
- if (domainLocale === currentLocale) {
233
- return false;
234
- }
235
- }
236
- return true;
237
- }
238
-
239
21
  const DELETED_EXPIRATION = /* @__PURE__ */ new Date(0);
240
22
  const DELETED_VALUE = "deleted";
241
- const responseSentSymbol$2 = Symbol.for("astro.responseSent");
23
+ const responseSentSymbol = Symbol.for("astro.responseSent");
242
24
  class AstroCookie {
243
25
  constructor(value) {
244
26
  this.value = value;
@@ -366,7 +148,7 @@ class AstroCookies {
366
148
  serialize(key, serializedValue, serializeOptions),
367
149
  true
368
150
  ]);
369
- if (this.#request[responseSentSymbol$2]) {
151
+ if (this.#request[responseSentSymbol]) {
370
152
  throw new AstroError({
371
153
  ...ResponseSentError
372
154
  });
@@ -421,9 +203,6 @@ const astroCookiesSymbol = Symbol.for("astro.cookies");
421
203
  function attachCookiesToResponse(response, cookies) {
422
204
  Reflect.set(response, astroCookiesSymbol, cookies);
423
205
  }
424
- function responseHasCookies(response) {
425
- return Reflect.has(response, astroCookiesSymbol);
426
- }
427
206
  function getFromResponse(response) {
428
207
  let cookies = Reflect.get(response, astroCookiesSymbol);
429
208
  if (cookies != null) {
@@ -458,44 +237,18 @@ const consoleLogDestination = {
458
237
  }
459
238
  };
460
239
 
461
- async function callMiddleware(onRequest, apiContext, responseFunction) {
462
- let nextCalled = false;
463
- let responseFunctionPromise = void 0;
464
- const next = async () => {
465
- nextCalled = true;
466
- responseFunctionPromise = responseFunction();
467
- return responseFunctionPromise;
468
- };
469
- let middlewarePromise = onRequest(apiContext, next);
470
- return await Promise.resolve(middlewarePromise).then(async (value) => {
471
- if (nextCalled) {
472
- if (typeof value !== "undefined") {
473
- if (value instanceof Response === false) {
474
- throw new AstroError(MiddlewareNotAResponse);
475
- }
476
- return ensureCookiesAttached(apiContext, value);
477
- } else {
478
- if (responseFunctionPromise) {
479
- return responseFunctionPromise;
480
- } else {
481
- throw new AstroError(MiddlewareNotAResponse);
482
- }
483
- }
484
- } else if (typeof value === "undefined") {
485
- throw new AstroError(MiddlewareNoDataOrNextCalled);
486
- } else if (value instanceof Response === false) {
487
- throw new AstroError(MiddlewareNotAResponse);
488
- } else {
489
- return ensureCookiesAttached(apiContext, value);
490
- }
491
- });
492
- }
493
- function ensureCookiesAttached(apiContext, response) {
494
- if (apiContext.cookies !== void 0 && !responseHasCookies(response)) {
495
- attachCookiesToResponse(response, apiContext.cookies);
240
+ const RedirectComponentInstance = {
241
+ default() {
242
+ return new Response(null, {
243
+ status: 301
244
+ });
496
245
  }
497
- return response;
498
- }
246
+ };
247
+ const RedirectSinglePageBuiltModule = {
248
+ page: () => Promise.resolve(RedirectComponentInstance),
249
+ onRequest: (_, next) => next(),
250
+ renderers: []
251
+ };
499
252
 
500
253
  function routeIsRedirect(route) {
501
254
  return route?.type === "redirect";
@@ -503,68 +256,116 @@ function routeIsRedirect(route) {
503
256
  function routeIsFallback(route) {
504
257
  return route?.type === "fallback";
505
258
  }
506
- function redirectRouteGenerate(redirectRoute, data) {
507
- const routeData = redirectRoute.redirectRoute;
508
- const route = redirectRoute.redirect;
509
- if (typeof routeData !== "undefined") {
510
- return routeData?.generate(data) || routeData?.pathname || "/";
511
- } else if (typeof route === "string") {
512
- let target = route;
513
- for (const param of Object.keys(data)) {
514
- const paramValue = data[param];
259
+
260
+ async function renderRedirect(renderContext) {
261
+ const {
262
+ request: { method },
263
+ routeData
264
+ } = renderContext;
265
+ const { redirect, redirectRoute } = routeData;
266
+ const status = redirectRoute && typeof redirect === "object" ? redirect.status : method === "GET" ? 301 : 308;
267
+ const headers = { location: redirectRouteGenerate(renderContext) };
268
+ return new Response(null, { status, headers });
269
+ }
270
+ function redirectRouteGenerate(renderContext) {
271
+ const {
272
+ params,
273
+ routeData: { redirect, redirectRoute }
274
+ } = renderContext;
275
+ if (typeof redirectRoute !== "undefined") {
276
+ return redirectRoute?.generate(params) || redirectRoute?.pathname || "/";
277
+ } else if (typeof redirect === "string") {
278
+ let target = redirect;
279
+ for (const param of Object.keys(params)) {
280
+ const paramValue = params[param];
515
281
  target = target.replace(`[${param}]`, paramValue);
516
282
  target = target.replace(`[...${param}]`, paramValue);
517
283
  }
518
284
  return target;
519
- } else if (typeof route === "undefined") {
285
+ } else if (typeof redirect === "undefined") {
520
286
  return "/";
521
287
  }
522
- return route.destination;
523
- }
524
- function redirectRouteStatus(redirectRoute, method = "GET") {
525
- const routeData = redirectRoute.redirectRoute;
526
- if (routeData && typeof redirectRoute.redirect === "object") {
527
- return redirectRoute.redirect.status;
528
- } else if (method !== "GET") {
529
- return 308;
530
- }
531
- return 301;
288
+ return redirect.destination;
532
289
  }
533
290
 
534
- const RedirectComponentInstance = {
535
- default() {
536
- return new Response(null, {
537
- status: 301
538
- });
539
- }
540
- };
541
- const RedirectSinglePageBuiltModule = {
542
- page: () => Promise.resolve(RedirectComponentInstance),
543
- onRequest: (_, next) => next(),
544
- renderers: []
545
- };
546
-
547
- const VALID_PARAM_TYPES = ["string", "number", "undefined"];
548
- function validateGetStaticPathsParameter([key, value], route) {
549
- if (!VALID_PARAM_TYPES.includes(typeof value)) {
550
- throw new AstroError({
551
- ...GetStaticPathsInvalidRouteParam,
552
- message: GetStaticPathsInvalidRouteParam.message(key, value, typeof value),
553
- location: {
554
- file: route
555
- }
556
- });
291
+ function createAssetLink(href, base, assetsPrefix) {
292
+ if (assetsPrefix) {
293
+ return joinPaths(assetsPrefix, slash(href));
294
+ } else if (base) {
295
+ return prependForwardSlash$1(joinPaths(base, slash(href)));
296
+ } else {
297
+ return href;
557
298
  }
558
299
  }
559
- function validateDynamicRouteModule(mod, {
560
- ssr,
561
- route
562
- }) {
563
- if ((!ssr || route.prerender) && !mod.getStaticPaths) {
564
- throw new AstroError({
565
- ...GetStaticPathsRequired,
566
- location: { file: route.component }
567
- });
300
+ function createStylesheetElement(stylesheet, base, assetsPrefix) {
301
+ if (stylesheet.type === "inline") {
302
+ return {
303
+ props: {},
304
+ children: stylesheet.content
305
+ };
306
+ } else {
307
+ return {
308
+ props: {
309
+ rel: "stylesheet",
310
+ href: createAssetLink(stylesheet.src, base, assetsPrefix)
311
+ },
312
+ children: ""
313
+ };
314
+ }
315
+ }
316
+ function createStylesheetElementSet(stylesheets, base, assetsPrefix) {
317
+ return new Set(stylesheets.map((s) => createStylesheetElement(s, base, assetsPrefix)));
318
+ }
319
+ function createModuleScriptElement(script, base, assetsPrefix) {
320
+ if (script.type === "external") {
321
+ return createModuleScriptElementWithSrc(script.value, base, assetsPrefix);
322
+ } else {
323
+ return {
324
+ props: {
325
+ type: "module"
326
+ },
327
+ children: script.value
328
+ };
329
+ }
330
+ }
331
+ function createModuleScriptElementWithSrc(src, base, assetsPrefix) {
332
+ return {
333
+ props: {
334
+ type: "module",
335
+ src: createAssetLink(src, base, assetsPrefix)
336
+ },
337
+ children: ""
338
+ };
339
+ }
340
+
341
+ function matchRoute(pathname, manifest) {
342
+ const decodedPathname = decodeURI(pathname);
343
+ return manifest.routes.find((route) => {
344
+ return route.pattern.test(decodedPathname) || route.fallbackRoutes.some((fallbackRoute) => fallbackRoute.pattern.test(decodedPathname));
345
+ });
346
+ }
347
+
348
+ const VALID_PARAM_TYPES = ["string", "number", "undefined"];
349
+ function validateGetStaticPathsParameter([key, value], route) {
350
+ if (!VALID_PARAM_TYPES.includes(typeof value)) {
351
+ throw new AstroError({
352
+ ...GetStaticPathsInvalidRouteParam,
353
+ message: GetStaticPathsInvalidRouteParam.message(key, value, typeof value),
354
+ location: {
355
+ file: route
356
+ }
357
+ });
358
+ }
359
+ }
360
+ function validateDynamicRouteModule(mod, {
361
+ ssr,
362
+ route
363
+ }) {
364
+ if ((!ssr || route.prerender) && !mod.getStaticPaths) {
365
+ throw new AstroError({
366
+ ...GetStaticPathsRequired,
367
+ location: { file: route.component }
368
+ });
568
369
  }
569
370
  }
570
371
  function validateGetStaticPathsResult(result, logger, route) {
@@ -613,20 +414,6 @@ function validateGetStaticPathsResult(result, logger, route) {
613
414
  });
614
415
  }
615
416
 
616
- function getParams(array) {
617
- const fn = (match) => {
618
- const params = {};
619
- array.forEach((key, i) => {
620
- if (key.startsWith("...")) {
621
- params[key.slice(3)] = match[i + 1] ? match[i + 1] : void 0;
622
- } else {
623
- params[key] = match[i + 1];
624
- }
625
- });
626
- return params;
627
- };
628
- return fn;
629
- }
630
417
  function stringifyParams(params, route) {
631
418
  const validatedParams = Object.entries(params).reduce((acc, next) => {
632
419
  validateGetStaticPathsParameter(next, route.component);
@@ -771,99 +558,334 @@ function findPathItemByKey(staticPaths, params, route, logger) {
771
558
  logger.debug("router", `findPathItemByKey() - Unexpected cache miss looking for ${paramsKey}`);
772
559
  }
773
560
 
774
- async function getParamsAndProps(opts) {
775
- const { logger, mod, route, routeCache, pathname, ssr } = opts;
776
- if (!route || route.pathname) {
777
- return [{}, {}];
778
- }
779
- const params = getRouteParams(route, pathname) ?? {};
780
- if (routeIsRedirect(route) || routeIsFallback(route)) {
781
- return [params, {}];
561
+ function shouldAppendForwardSlash(trailingSlash, buildFormat) {
562
+ switch (trailingSlash) {
563
+ case "always":
564
+ return true;
565
+ case "never":
566
+ return false;
567
+ case "ignore": {
568
+ switch (buildFormat) {
569
+ case "directory":
570
+ return true;
571
+ case "preserve":
572
+ case "file":
573
+ return false;
574
+ }
575
+ }
782
576
  }
783
- if (mod) {
784
- validatePrerenderEndpointCollision(route, mod, params);
577
+ }
578
+
579
+ function getPathByLocale(locale, locales) {
580
+ for (const loopLocale of locales) {
581
+ if (typeof loopLocale === "string") {
582
+ if (loopLocale === locale) {
583
+ return loopLocale;
584
+ }
585
+ } else {
586
+ for (const code of loopLocale.codes) {
587
+ if (code === locale) {
588
+ return loopLocale.path;
589
+ }
590
+ }
591
+ }
785
592
  }
786
- const staticPaths = await callGetStaticPaths({
787
- mod,
788
- route,
789
- routeCache,
790
- logger,
791
- ssr
593
+ throw new Unreachable();
594
+ }
595
+ function normalizeTheLocale(locale) {
596
+ return locale.replaceAll("_", "-").toLowerCase();
597
+ }
598
+ function toCodes(locales) {
599
+ return locales.map((loopLocale) => {
600
+ if (typeof loopLocale === "string") {
601
+ return loopLocale;
602
+ } else {
603
+ return loopLocale.codes[0];
604
+ }
792
605
  });
793
- const matchedStaticPath = findPathItemByKey(staticPaths, params, route, logger);
794
- if (!matchedStaticPath && (ssr ? route.prerender : true)) {
795
- throw new AstroError({
796
- ...NoMatchingStaticPathFound,
797
- message: NoMatchingStaticPathFound.message(pathname),
798
- hint: NoMatchingStaticPathFound.hint([route.component])
799
- });
606
+ }
607
+ class Unreachable extends Error {
608
+ constructor() {
609
+ super(
610
+ "Astro encountered an unexpected line of code.\nIn most cases, this is not your fault, but a bug in astro code.\nIf there isn't one already, please create an issue.\nhttps://astro.build/issues"
611
+ );
800
612
  }
801
- const props = matchedStaticPath?.props ? { ...matchedStaticPath.props } : {};
802
- return [params, props];
803
613
  }
804
- function getRouteParams(route, pathname) {
805
- if (route.params.length) {
806
- const paramsMatch = route.pattern.exec(decodeURIComponent(pathname));
807
- if (paramsMatch) {
808
- return getParams(route.params)(paramsMatch);
614
+
615
+ function pathnameHasLocale(pathname, locales) {
616
+ const segments = pathname.split("/");
617
+ for (const segment of segments) {
618
+ for (const locale of locales) {
619
+ if (typeof locale === "string") {
620
+ if (normalizeTheLocale(segment) === normalizeTheLocale(locale)) {
621
+ return true;
622
+ }
623
+ } else if (segment === locale.path) {
624
+ return true;
625
+ }
809
626
  }
810
627
  }
628
+ return false;
811
629
  }
812
- function validatePrerenderEndpointCollision(route, mod, params) {
813
- if (route.type === "endpoint" && mod.getStaticPaths) {
814
- const lastSegment = route.segments[route.segments.length - 1];
815
- const paramValues = Object.values(params);
816
- const lastParam = paramValues[paramValues.length - 1];
817
- if (lastSegment.length === 1 && lastSegment[0].dynamic && lastParam === void 0) {
818
- throw new AstroError({
819
- ...PrerenderDynamicEndpointPathCollide,
820
- message: PrerenderDynamicEndpointPathCollide.message(route.route),
821
- hint: PrerenderDynamicEndpointPathCollide.hint(route.component),
822
- location: {
823
- file: route.component
630
+ function createI18nMiddleware(i18n, base, trailingSlash, buildFormat) {
631
+ if (!i18n)
632
+ return (_, next) => next();
633
+ const prefixAlways = (url, response, context) => {
634
+ if (url.pathname === base + "/" || url.pathname === base) {
635
+ if (shouldAppendForwardSlash(trailingSlash, buildFormat)) {
636
+ return context.redirect(`${appendForwardSlash$1(joinPaths(base, i18n.defaultLocale))}`);
637
+ } else {
638
+ return context.redirect(`${joinPaths(base, i18n.defaultLocale)}`);
639
+ }
640
+ } else if (!pathnameHasLocale(url.pathname, i18n.locales)) {
641
+ return new Response(null, {
642
+ status: 404,
643
+ headers: response.headers
644
+ });
645
+ }
646
+ return void 0;
647
+ };
648
+ const prefixOtherLocales = (url, response) => {
649
+ let pathnameContainsDefaultLocale = false;
650
+ for (const segment of url.pathname.split("/")) {
651
+ if (normalizeTheLocale(segment) === normalizeTheLocale(i18n.defaultLocale)) {
652
+ pathnameContainsDefaultLocale = true;
653
+ break;
654
+ }
655
+ }
656
+ if (pathnameContainsDefaultLocale) {
657
+ const newLocation = url.pathname.replace(`/${i18n.defaultLocale}`, "");
658
+ response.headers.set("Location", newLocation);
659
+ return new Response(null, {
660
+ status: 404,
661
+ headers: response.headers
662
+ });
663
+ }
664
+ return void 0;
665
+ };
666
+ const prefixAlwaysNoRedirect = (url, response) => {
667
+ const isRoot = url.pathname === base + "/" || url.pathname === base;
668
+ if (!(isRoot || pathnameHasLocale(url.pathname, i18n.locales))) {
669
+ return new Response(null, {
670
+ status: 404,
671
+ headers: response.headers
672
+ });
673
+ }
674
+ return void 0;
675
+ };
676
+ return async (context, next) => {
677
+ const response = await next();
678
+ const type = response.headers.get(ROUTE_TYPE_HEADER);
679
+ if (type !== "page" && type !== "fallback") {
680
+ return response;
681
+ }
682
+ const { url, currentLocale } = context;
683
+ const { locales, defaultLocale, fallback, strategy } = i18n;
684
+ switch (i18n.strategy) {
685
+ case "domains-prefix-other-locales": {
686
+ if (localeHasntDomain(i18n, currentLocale)) {
687
+ const result = prefixOtherLocales(url, response);
688
+ if (result) {
689
+ return result;
690
+ }
691
+ }
692
+ break;
693
+ }
694
+ case "pathname-prefix-other-locales": {
695
+ const result = prefixOtherLocales(url, response);
696
+ if (result) {
697
+ return result;
698
+ }
699
+ break;
700
+ }
701
+ case "domains-prefix-always-no-redirect": {
702
+ if (localeHasntDomain(i18n, currentLocale)) {
703
+ const result = prefixAlwaysNoRedirect(url, response);
704
+ if (result) {
705
+ return result;
706
+ }
707
+ }
708
+ break;
709
+ }
710
+ case "pathname-prefix-always-no-redirect": {
711
+ const result = prefixAlwaysNoRedirect(url, response);
712
+ if (result) {
713
+ return result;
714
+ }
715
+ break;
716
+ }
717
+ case "pathname-prefix-always": {
718
+ const result = prefixAlways(url, response, context);
719
+ if (result) {
720
+ return result;
721
+ }
722
+ break;
723
+ }
724
+ case "domains-prefix-always": {
725
+ if (localeHasntDomain(i18n, currentLocale)) {
726
+ const result = prefixAlways(url, response, context);
727
+ if (result) {
728
+ return result;
729
+ }
824
730
  }
731
+ break;
732
+ }
733
+ }
734
+ if (response.status >= 300 && fallback) {
735
+ const fallbackKeys = i18n.fallback ? Object.keys(i18n.fallback) : [];
736
+ const segments = url.pathname.split("/");
737
+ const urlLocale = segments.find((segment) => {
738
+ for (const locale of locales) {
739
+ if (typeof locale === "string") {
740
+ if (locale === segment) {
741
+ return true;
742
+ }
743
+ } else if (locale.path === segment) {
744
+ return true;
745
+ }
746
+ }
747
+ return false;
825
748
  });
749
+ if (urlLocale && fallbackKeys.includes(urlLocale)) {
750
+ const fallbackLocale = fallback[urlLocale];
751
+ const pathFallbackLocale = getPathByLocale(fallbackLocale, locales);
752
+ let newPathname;
753
+ if (pathFallbackLocale === defaultLocale && strategy === "pathname-prefix-other-locales") {
754
+ newPathname = url.pathname.replace(`/${urlLocale}`, ``);
755
+ } else {
756
+ newPathname = url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`);
757
+ }
758
+ return context.redirect(newPathname);
759
+ }
760
+ }
761
+ return response;
762
+ };
763
+ }
764
+ function localeHasntDomain(i18n, currentLocale) {
765
+ for (const domainLocale of Object.values(i18n.domainLookupTable)) {
766
+ if (domainLocale === currentLocale) {
767
+ return false;
826
768
  }
827
769
  }
770
+ return true;
828
771
  }
829
772
 
830
- const clientLocalsSymbol$1 = Symbol.for("astro.locals");
831
- const routeDataSymbol = Symbol.for(ROUTE_DATA_SYMBOL);
832
- async function createRenderContext(options) {
833
- const request = options.request;
834
- const pathname = options.pathname ?? new URL(request.url).pathname;
835
- const [params, props] = await getParamsAndProps({
836
- mod: options.mod,
837
- route: options.route,
838
- routeCache: options.env.routeCache,
839
- pathname,
840
- logger: options.env.logger,
841
- ssr: options.env.ssr
842
- });
843
- const context = {
844
- ...options,
845
- pathname,
846
- params,
847
- props,
848
- locales: options.locales,
849
- routing: options.routing,
850
- defaultLocale: options.defaultLocale
773
+ class Pipeline {
774
+ constructor(logger, manifest, mode, renderers, resolve, serverLike, streaming, adapterName = manifest.adapterName, clientDirectives = manifest.clientDirectives, compressHTML = manifest.compressHTML, i18n = manifest.i18n, middleware = manifest.middleware, routeCache = new RouteCache(logger, mode), site = manifest.site) {
775
+ this.logger = logger;
776
+ this.manifest = manifest;
777
+ this.mode = mode;
778
+ this.renderers = renderers;
779
+ this.resolve = resolve;
780
+ this.serverLike = serverLike;
781
+ this.streaming = streaming;
782
+ this.adapterName = adapterName;
783
+ this.clientDirectives = clientDirectives;
784
+ this.compressHTML = compressHTML;
785
+ this.i18n = i18n;
786
+ this.middleware = middleware;
787
+ this.routeCache = routeCache;
788
+ this.site = site;
789
+ this.internalMiddleware = [
790
+ createI18nMiddleware(i18n, manifest.base, manifest.trailingSlash, manifest.buildFormat)
791
+ ];
792
+ }
793
+ internalMiddleware;
794
+ }
795
+
796
+ class AppPipeline extends Pipeline {
797
+ static create({
798
+ logger,
799
+ manifest,
800
+ mode,
801
+ renderers,
802
+ resolve,
803
+ serverLike,
804
+ streaming
805
+ }) {
806
+ return new AppPipeline(logger, manifest, mode, renderers, resolve, serverLike, streaming);
807
+ }
808
+ headElements(routeData) {
809
+ const routeInfo = this.manifest.routes.find((route) => route.routeData === routeData);
810
+ const links = /* @__PURE__ */ new Set();
811
+ const scripts = /* @__PURE__ */ new Set();
812
+ const styles = createStylesheetElementSet(routeInfo?.styles ?? []);
813
+ for (const script of routeInfo?.scripts ?? []) {
814
+ if ("stage" in script) {
815
+ if (script.stage === "head-inline") {
816
+ scripts.add({
817
+ props: {},
818
+ children: script.children
819
+ });
820
+ }
821
+ } else {
822
+ scripts.add(createModuleScriptElement(script));
823
+ }
824
+ }
825
+ return { links, styles, scripts };
826
+ }
827
+ componentMetadata() {
828
+ }
829
+ }
830
+
831
+ async function callMiddleware(onRequest, apiContext, responseFunction) {
832
+ let nextCalled = false;
833
+ let responseFunctionPromise = void 0;
834
+ const next = async () => {
835
+ nextCalled = true;
836
+ responseFunctionPromise = responseFunction();
837
+ return responseFunctionPromise;
851
838
  };
852
- Object.defineProperty(context, "locals", {
853
- enumerable: true,
854
- get() {
855
- return Reflect.get(request, clientLocalsSymbol$1);
856
- },
857
- set(val) {
858
- if (typeof val !== "object") {
859
- throw new AstroError(LocalsNotAnObject);
839
+ let middlewarePromise = onRequest(apiContext, next);
840
+ return await Promise.resolve(middlewarePromise).then(async (value) => {
841
+ if (nextCalled) {
842
+ if (typeof value !== "undefined") {
843
+ if (value instanceof Response === false) {
844
+ throw new AstroError(MiddlewareNotAResponse);
845
+ }
846
+ return value;
860
847
  } else {
861
- Reflect.set(request, clientLocalsSymbol$1, val);
848
+ if (responseFunctionPromise) {
849
+ return responseFunctionPromise;
850
+ } else {
851
+ throw new AstroError(MiddlewareNotAResponse);
852
+ }
862
853
  }
854
+ } else if (typeof value === "undefined") {
855
+ throw new AstroError(MiddlewareNoDataOrNextCalled);
856
+ } else if (value instanceof Response === false) {
857
+ throw new AstroError(MiddlewareNotAResponse);
858
+ } else {
859
+ return value;
863
860
  }
864
861
  });
865
- return context;
866
862
  }
863
+
864
+ function sequence(...handlers) {
865
+ const filtered = handlers.filter((h) => !!h);
866
+ const length = filtered.length;
867
+ if (!length) {
868
+ const handler = defineMiddleware((context, next) => {
869
+ return next();
870
+ });
871
+ return handler;
872
+ }
873
+ return defineMiddleware((context, next) => {
874
+ return applyHandle(0, context);
875
+ function applyHandle(i, handleContext) {
876
+ const handle = filtered[i];
877
+ const result = handle(handleContext, async () => {
878
+ if (i < length - 1) {
879
+ return applyHandle(i + 1, handleContext);
880
+ } else {
881
+ return next();
882
+ }
883
+ });
884
+ return result;
885
+ }
886
+ });
887
+ }
888
+
867
889
  function parseLocale(header) {
868
890
  if (header === "*") {
869
891
  return [{ locale: header, qualityValue: void 0 }];
@@ -952,262 +974,124 @@ function computePreferredLocaleList(request, locales) {
952
974
  return locale;
953
975
  } else {
954
976
  return locale.codes.at(0);
955
- }
956
- });
957
- } else if (browserLocaleList.length > 0) {
958
- for (const browserLocale of browserLocaleList) {
959
- for (const loopLocale of locales) {
960
- if (typeof loopLocale === "string") {
961
- if (normalizeTheLocale(loopLocale) === normalizeTheLocale(browserLocale.locale)) {
962
- result.push(loopLocale);
963
- }
964
- } else {
965
- for (const code of loopLocale.codes) {
966
- if (code === browserLocale.locale) {
967
- result.push(loopLocale.path);
968
- }
969
- }
970
- }
971
- }
972
- }
973
- }
974
- }
975
- return result;
976
- }
977
- function computeCurrentLocale(request, locales, routingStrategy, defaultLocale) {
978
- const routeData = Reflect.get(request, routeDataSymbol);
979
- if (!routeData) {
980
- return defaultLocale;
981
- }
982
- for (const segment of routeData.route.split("/")) {
983
- for (const locale of locales) {
984
- if (typeof locale === "string") {
985
- if (normalizeTheLocale(locale) === normalizeTheLocale(segment)) {
986
- return locale;
987
- }
988
- } else {
989
- if (locale.path === segment) {
990
- return locale.codes.at(0);
991
- }
992
- }
993
- }
994
- }
995
- if (routingStrategy === "pathname-prefix-other-locales" || routingStrategy === "domains-prefix-other-locales") {
996
- return defaultLocale;
997
- }
998
- return void 0;
999
- }
1000
-
1001
- function createEnvironment(options) {
1002
- return options;
1003
- }
1004
-
1005
- const clientAddressSymbol$3 = Symbol.for("astro.clientAddress");
1006
- const clientLocalsSymbol = Symbol.for("astro.locals");
1007
- function createAPIContext({
1008
- request,
1009
- params,
1010
- site,
1011
- props,
1012
- adapterName,
1013
- locales,
1014
- routingStrategy,
1015
- defaultLocale
1016
- }) {
1017
- let preferredLocale = void 0;
1018
- let preferredLocaleList = void 0;
1019
- let currentLocale = void 0;
1020
- const context = {
1021
- cookies: new AstroCookies(request),
1022
- request,
1023
- params,
1024
- site: site ? new URL(site) : void 0,
1025
- generator: `Astro v${ASTRO_VERSION}`,
1026
- props,
1027
- redirect(path, status) {
1028
- return new Response(null, {
1029
- status: status || 302,
1030
- headers: {
1031
- Location: path
1032
- }
1033
- });
1034
- },
1035
- get preferredLocale() {
1036
- if (preferredLocale) {
1037
- return preferredLocale;
1038
- }
1039
- if (locales) {
1040
- preferredLocale = computePreferredLocale(request, locales);
1041
- return preferredLocale;
1042
- }
1043
- return void 0;
1044
- },
1045
- get preferredLocaleList() {
1046
- if (preferredLocaleList) {
1047
- return preferredLocaleList;
1048
- }
1049
- if (locales) {
1050
- preferredLocaleList = computePreferredLocaleList(request, locales);
1051
- return preferredLocaleList;
1052
- }
1053
- return void 0;
1054
- },
1055
- get currentLocale() {
1056
- if (currentLocale) {
1057
- return currentLocale;
1058
- }
1059
- if (locales) {
1060
- currentLocale = computeCurrentLocale(request, locales, routingStrategy, defaultLocale);
1061
- }
1062
- return currentLocale;
1063
- },
1064
- url: new URL(request.url),
1065
- get clientAddress() {
1066
- if (clientAddressSymbol$3 in request) {
1067
- return Reflect.get(request, clientAddressSymbol$3);
1068
- }
1069
- if (adapterName) {
1070
- throw new AstroError({
1071
- ...ClientAddressNotAvailable,
1072
- message: ClientAddressNotAvailable.message(adapterName)
1073
- });
1074
- } else {
1075
- throw new AstroError(StaticClientAddressNotAvailable);
1076
- }
1077
- },
1078
- get locals() {
1079
- let locals = Reflect.get(request, clientLocalsSymbol);
1080
- if (locals === void 0) {
1081
- locals = {};
1082
- Reflect.set(request, clientLocalsSymbol, locals);
1083
- }
1084
- if (typeof locals !== "object") {
1085
- throw new AstroError(LocalsNotAnObject);
1086
- }
1087
- return locals;
1088
- },
1089
- // We define a custom property, so we can check the value passed to locals
1090
- set locals(val) {
1091
- if (typeof val !== "object") {
1092
- throw new AstroError(LocalsNotAnObject);
1093
- } else {
1094
- Reflect.set(request, clientLocalsSymbol, val);
977
+ }
978
+ });
979
+ } else if (browserLocaleList.length > 0) {
980
+ for (const browserLocale of browserLocaleList) {
981
+ for (const loopLocale of locales) {
982
+ if (typeof loopLocale === "string") {
983
+ if (normalizeTheLocale(loopLocale) === normalizeTheLocale(browserLocale.locale)) {
984
+ result.push(loopLocale);
985
+ }
986
+ } else {
987
+ for (const code of loopLocale.codes) {
988
+ if (code === browserLocale.locale) {
989
+ result.push(loopLocale.path);
990
+ }
991
+ }
992
+ }
993
+ }
1095
994
  }
1096
995
  }
1097
- };
1098
- return context;
1099
- }
1100
- async function callEndpoint(mod, env, ctx, onRequest) {
1101
- const context = createAPIContext({
1102
- request: ctx.request,
1103
- params: ctx.params,
1104
- props: ctx.props,
1105
- site: env.site,
1106
- adapterName: env.adapterName,
1107
- routingStrategy: ctx.routing,
1108
- defaultLocale: ctx.defaultLocale,
1109
- locales: ctx.locales
1110
- });
1111
- let response;
1112
- if (onRequest) {
1113
- response = await callMiddleware(onRequest, context, async () => {
1114
- return await renderEndpoint(mod, context, env.ssr, env.logger);
1115
- });
1116
- } else {
1117
- response = await renderEndpoint(mod, context, env.ssr, env.logger);
1118
996
  }
1119
- attachCookiesToResponse(response, context.cookies);
1120
- return response;
997
+ return result;
1121
998
  }
1122
-
1123
- function sequence(...handlers) {
1124
- const filtered = handlers.filter((h) => !!h);
1125
- const length = filtered.length;
1126
- if (!length) {
1127
- const handler = defineMiddleware((context, next) => {
1128
- return next();
1129
- });
1130
- return handler;
1131
- }
1132
- return defineMiddleware((context, next) => {
1133
- return applyHandle(0, context);
1134
- function applyHandle(i, handleContext) {
1135
- const handle = filtered[i];
1136
- const result = handle(handleContext, async () => {
1137
- if (i < length - 1) {
1138
- return applyHandle(i + 1, handleContext);
999
+ function computeCurrentLocale(pathname, locales, routingStrategy, defaultLocale) {
1000
+ for (const segment of pathname.split("/")) {
1001
+ for (const locale of locales) {
1002
+ if (typeof locale === "string") {
1003
+ if (!segment.includes(locale))
1004
+ continue;
1005
+ if (normalizeTheLocale(locale) === normalizeTheLocale(segment)) {
1006
+ return locale;
1007
+ }
1008
+ } else {
1009
+ if (locale.path === segment) {
1010
+ return locale.codes.at(0);
1139
1011
  } else {
1140
- return next();
1012
+ for (const code of locale.codes) {
1013
+ if (normalizeTheLocale(code) === normalizeTheLocale(segment)) {
1014
+ return code;
1015
+ }
1016
+ }
1141
1017
  }
1142
- });
1143
- return result;
1018
+ }
1144
1019
  }
1145
- });
1020
+ }
1021
+ if (routingStrategy === "pathname-prefix-other-locales" || routingStrategy === "domains-prefix-other-locales") {
1022
+ return defaultLocale;
1023
+ }
1024
+ return void 0;
1146
1025
  }
1147
1026
 
1148
1027
  function defineMiddleware(fn) {
1149
1028
  return fn;
1150
1029
  }
1151
1030
 
1152
- function createAssetLink(href, base, assetsPrefix) {
1153
- if (assetsPrefix) {
1154
- return joinPaths(assetsPrefix, slash(href));
1155
- } else if (base) {
1156
- return prependForwardSlash$1(joinPaths(base, slash(href)));
1157
- } else {
1158
- return href;
1031
+ async function getProps(opts) {
1032
+ const { logger, mod, routeData: route, routeCache, pathname, serverLike } = opts;
1033
+ if (!route || route.pathname) {
1034
+ return {};
1159
1035
  }
1160
- }
1161
- function createStylesheetElement(stylesheet, base, assetsPrefix) {
1162
- if (stylesheet.type === "inline") {
1163
- return {
1164
- props: {},
1165
- children: stylesheet.content
1166
- };
1167
- } else {
1168
- return {
1169
- props: {
1170
- rel: "stylesheet",
1171
- href: createAssetLink(stylesheet.src, base, assetsPrefix)
1172
- },
1173
- children: ""
1174
- };
1036
+ if (routeIsRedirect(route) || routeIsFallback(route)) {
1037
+ return {};
1175
1038
  }
1176
- }
1177
- function createStylesheetElementSet(stylesheets, base, assetsPrefix) {
1178
- return new Set(stylesheets.map((s) => createStylesheetElement(s, base, assetsPrefix)));
1179
- }
1180
- function createModuleScriptElement(script, base, assetsPrefix) {
1181
- if (script.type === "external") {
1182
- return createModuleScriptElementWithSrc(script.value, base, assetsPrefix);
1183
- } else {
1184
- return {
1185
- props: {
1186
- type: "module"
1187
- },
1188
- children: script.value
1189
- };
1039
+ const params = getParams(route, pathname);
1040
+ if (mod) {
1041
+ validatePrerenderEndpointCollision(route, mod, params);
1190
1042
  }
1191
- }
1192
- function createModuleScriptElementWithSrc(src, base, assetsPrefix) {
1193
- return {
1194
- props: {
1195
- type: "module",
1196
- src: createAssetLink(src, base, assetsPrefix)
1197
- },
1198
- children: ""
1199
- };
1200
- }
1201
-
1202
- function matchRoute(pathname, manifest) {
1203
- const decodedPathname = decodeURI(pathname);
1204
- return manifest.routes.find((route) => {
1205
- return route.pattern.test(decodedPathname) || route.fallbackRoutes.some((fallbackRoute) => fallbackRoute.pattern.test(decodedPathname));
1043
+ const staticPaths = await callGetStaticPaths({
1044
+ mod,
1045
+ route,
1046
+ routeCache,
1047
+ logger,
1048
+ ssr: serverLike
1049
+ });
1050
+ const matchedStaticPath = findPathItemByKey(staticPaths, params, route, logger);
1051
+ if (!matchedStaticPath && (serverLike ? route.prerender : true)) {
1052
+ throw new AstroError({
1053
+ ...NoMatchingStaticPathFound,
1054
+ message: NoMatchingStaticPathFound.message(pathname),
1055
+ hint: NoMatchingStaticPathFound.hint([route.component])
1056
+ });
1057
+ }
1058
+ const props = matchedStaticPath?.props ? { ...matchedStaticPath.props } : {};
1059
+ return props;
1060
+ }
1061
+ function getParams(route, pathname) {
1062
+ if (!route.params.length)
1063
+ return {};
1064
+ const paramsMatch = route.pattern.exec(decodeURIComponent(pathname));
1065
+ if (!paramsMatch)
1066
+ return {};
1067
+ const params = {};
1068
+ route.params.forEach((key, i) => {
1069
+ if (key.startsWith("...")) {
1070
+ params[key.slice(3)] = paramsMatch[i + 1] ? paramsMatch[i + 1] : void 0;
1071
+ } else {
1072
+ params[key] = paramsMatch[i + 1];
1073
+ }
1206
1074
  });
1075
+ return params;
1076
+ }
1077
+ function validatePrerenderEndpointCollision(route, mod, params) {
1078
+ if (route.type === "endpoint" && mod.getStaticPaths) {
1079
+ const lastSegment = route.segments[route.segments.length - 1];
1080
+ const paramValues = Object.values(params);
1081
+ const lastParam = paramValues[paramValues.length - 1];
1082
+ if (lastSegment.length === 1 && lastSegment[0].dynamic && lastParam === void 0) {
1083
+ throw new AstroError({
1084
+ ...PrerenderDynamicEndpointPathCollide,
1085
+ message: PrerenderDynamicEndpointPathCollide.message(route.route),
1086
+ hint: PrerenderDynamicEndpointPathCollide.hint(route.component),
1087
+ location: {
1088
+ file: route.component
1089
+ }
1090
+ });
1091
+ }
1092
+ }
1207
1093
  }
1208
1094
 
1209
- const clientAddressSymbol$2 = Symbol.for("astro.clientAddress");
1210
- const responseSentSymbol$1 = Symbol.for("astro.responseSent");
1211
1095
  function getFunctionExpression(slot) {
1212
1096
  if (!slot)
1213
1097
  return;
@@ -1312,7 +1196,7 @@ function createResult(args) {
1312
1196
  // @ts-expect-error
1313
1197
  __proto__: astroGlobal,
1314
1198
  get clientAddress() {
1315
- if (!(clientAddressSymbol$2 in request)) {
1199
+ if (!(clientAddressSymbol$1 in request)) {
1316
1200
  if (args.adapterName) {
1317
1201
  throw new AstroError({
1318
1202
  ...ClientAddressNotAvailable,
@@ -1322,7 +1206,7 @@ function createResult(args) {
1322
1206
  throw new AstroError(StaticClientAddressNotAvailable);
1323
1207
  }
1324
1208
  }
1325
- return Reflect.get(request, clientAddressSymbol$2);
1209
+ return Reflect.get(request, clientAddressSymbol$1);
1326
1210
  },
1327
1211
  get cookies() {
1328
1212
  if (cookies) {
@@ -1358,9 +1242,9 @@ function createResult(args) {
1358
1242
  }
1359
1243
  if (args.locales) {
1360
1244
  currentLocale = computeCurrentLocale(
1361
- request,
1245
+ url.pathname,
1362
1246
  args.locales,
1363
- args.routingStrategy,
1247
+ args.strategy,
1364
1248
  args.defaultLocale
1365
1249
  );
1366
1250
  if (currentLocale) {
@@ -1407,177 +1291,205 @@ function createResult(args) {
1407
1291
  return result;
1408
1292
  }
1409
1293
 
1410
- async function renderPage({ mod, renderContext, env, cookies }) {
1411
- if (routeIsRedirect(renderContext.route)) {
1412
- return new Response(null, {
1413
- status: redirectRouteStatus(renderContext.route, renderContext.request.method),
1414
- headers: {
1415
- location: redirectRouteGenerate(renderContext.route, renderContext.params)
1416
- }
1417
- });
1418
- } else if (routeIsFallback(renderContext.route)) {
1419
- return new Response(null, {
1420
- status: 404
1421
- });
1422
- } else if (!mod) {
1423
- throw new AstroError(CantRenderPage);
1424
- }
1425
- const Component = mod.default;
1426
- if (!Component)
1427
- throw new Error(`Expected an exported Astro component but received typeof ${typeof Component}`);
1428
- const result = createResult({
1429
- adapterName: env.adapterName,
1430
- links: renderContext.links,
1431
- styles: renderContext.styles,
1432
- logger: env.logger,
1433
- params: renderContext.params,
1434
- pathname: renderContext.pathname,
1435
- componentMetadata: renderContext.componentMetadata,
1436
- resolve: env.resolve,
1437
- renderers: env.renderers,
1438
- clientDirectives: env.clientDirectives,
1439
- compressHTML: env.compressHTML,
1440
- request: renderContext.request,
1441
- partial: !!mod.partial,
1442
- site: env.site,
1443
- scripts: renderContext.scripts,
1444
- ssr: env.ssr,
1445
- status: renderContext.status ?? 200,
1446
- cookies,
1447
- locals: renderContext.locals ?? {},
1448
- locales: renderContext.locales,
1449
- defaultLocale: renderContext.defaultLocale,
1450
- routingStrategy: renderContext.routing
1451
- });
1452
- const response = await renderPage$1(
1453
- result,
1454
- Component,
1455
- renderContext.props,
1456
- {},
1457
- env.streaming,
1458
- renderContext.route
1459
- );
1460
- if (result.cookies) {
1461
- attachCookiesToResponse(response, result.cookies);
1462
- }
1463
- return response;
1464
- }
1465
-
1466
- class Pipeline {
1467
- env;
1468
- #onRequest;
1469
- #hooks = {
1470
- before: []
1471
- };
1472
- /**
1473
- * When creating a pipeline, an environment is mandatory.
1474
- * The environment won't change for the whole lifetime of the pipeline.
1475
- */
1476
- constructor(env) {
1477
- this.env = env;
1478
- }
1479
- setEnvironment() {
1480
- }
1481
- /**
1482
- * A middleware function that will be called before each request.
1483
- */
1484
- setMiddlewareFunction(onRequest) {
1485
- this.#onRequest = onRequest;
1486
- }
1487
- /**
1488
- * Removes the current middleware function. Subsequent requests won't trigger any middleware.
1489
- */
1490
- unsetMiddlewareFunction() {
1491
- this.#onRequest = void 0;
1492
- }
1493
- /**
1494
- * Returns the current environment
1495
- */
1496
- getEnvironment() {
1497
- return this.env;
1498
- }
1499
- /**
1500
- * The main function of the pipeline. Use this function to render any route known to Astro;
1501
- */
1502
- async renderRoute(renderContext, componentInstance) {
1503
- for (const hook of this.#hooks.before) {
1504
- hook(renderContext, componentInstance);
1505
- }
1506
- return await this.#tryRenderRoute(renderContext, this.env, componentInstance, this.#onRequest);
1294
+ class RenderContext {
1295
+ constructor(pipeline, locals, middleware, pathname, request, routeData, status, cookies = new AstroCookies(request), params = getParams(routeData, pathname)) {
1296
+ this.pipeline = pipeline;
1297
+ this.locals = locals;
1298
+ this.middleware = middleware;
1299
+ this.pathname = pathname;
1300
+ this.request = request;
1301
+ this.routeData = routeData;
1302
+ this.status = status;
1303
+ this.cookies = cookies;
1304
+ this.params = params;
1305
+ }
1306
+ static create({
1307
+ locals = {},
1308
+ middleware,
1309
+ pathname,
1310
+ pipeline,
1311
+ request,
1312
+ routeData,
1313
+ status = 200
1314
+ }) {
1315
+ return new RenderContext(
1316
+ pipeline,
1317
+ locals,
1318
+ sequence(...pipeline.internalMiddleware, middleware ?? pipeline.middleware),
1319
+ pathname,
1320
+ request,
1321
+ routeData,
1322
+ status
1323
+ );
1507
1324
  }
1508
1325
  /**
1326
+ * The main function of the RenderContext.
1327
+ *
1328
+ * Use this function to render any route known to Astro.
1509
1329
  * It attempts to render a route. A route can be a:
1330
+ *
1510
1331
  * - page
1511
1332
  * - redirect
1512
1333
  * - endpoint
1513
- *
1514
- * ## Errors
1515
- *
1516
- * It throws an error if the page can't be rendered.
1334
+ * - fallback
1517
1335
  */
1518
- async #tryRenderRoute(renderContext, env, mod, onRequest) {
1519
- const apiContext = createAPIContext({
1520
- request: renderContext.request,
1521
- params: renderContext.params,
1522
- props: renderContext.props,
1523
- site: env.site,
1524
- adapterName: env.adapterName,
1525
- locales: renderContext.locales,
1526
- routingStrategy: renderContext.routing,
1527
- defaultLocale: renderContext.defaultLocale
1336
+ async render(componentInstance) {
1337
+ const { cookies, middleware, pathname, pipeline, routeData } = this;
1338
+ const { logger, routeCache, serverLike, streaming } = pipeline;
1339
+ const props = await getProps({
1340
+ mod: componentInstance,
1341
+ routeData,
1342
+ routeCache,
1343
+ pathname,
1344
+ logger,
1345
+ serverLike
1528
1346
  });
1529
- switch (renderContext.route.type) {
1530
- case "page":
1531
- case "fallback":
1532
- case "redirect": {
1533
- if (onRequest) {
1534
- return await callMiddleware(onRequest, apiContext, () => {
1535
- return renderPage({
1536
- mod,
1537
- renderContext,
1538
- env,
1539
- cookies: apiContext.cookies
1540
- });
1347
+ const apiContext = this.createAPIContext(props);
1348
+ const { type } = routeData;
1349
+ const lastNext = type === "endpoint" ? () => renderEndpoint(componentInstance, apiContext, serverLike, logger) : type === "redirect" ? () => renderRedirect(this) : type === "page" ? async () => {
1350
+ const result = await this.createResult(componentInstance);
1351
+ const response2 = await renderPage(
1352
+ result,
1353
+ componentInstance?.default,
1354
+ props,
1355
+ {},
1356
+ streaming,
1357
+ routeData
1358
+ );
1359
+ response2.headers.set(ROUTE_TYPE_HEADER, "page");
1360
+ return response2;
1361
+ } : type === "fallback" ? () => new Response(null, { status: 500, headers: { [ROUTE_TYPE_HEADER]: "fallback" } }) : () => {
1362
+ throw new Error("Unknown type of route: " + type);
1363
+ };
1364
+ const response = await callMiddleware(middleware, apiContext, lastNext);
1365
+ if (response.headers.get(ROUTE_TYPE_HEADER)) {
1366
+ response.headers.delete(ROUTE_TYPE_HEADER);
1367
+ }
1368
+ attachCookiesToResponse(response, cookies);
1369
+ return response;
1370
+ }
1371
+ createAPIContext(props) {
1372
+ const renderContext = this;
1373
+ const { cookies, i18nData, params, pipeline, request } = this;
1374
+ const { currentLocale, preferredLocale, preferredLocaleList } = i18nData;
1375
+ const generator = `Astro v${ASTRO_VERSION}`;
1376
+ const redirect = (path, status = 302) => new Response(null, { status, headers: { Location: path } });
1377
+ const site = pipeline.site ? new URL(pipeline.site) : void 0;
1378
+ const url = new URL(request.url);
1379
+ return {
1380
+ cookies,
1381
+ currentLocale,
1382
+ generator,
1383
+ params,
1384
+ preferredLocale,
1385
+ preferredLocaleList,
1386
+ props,
1387
+ redirect,
1388
+ request,
1389
+ site,
1390
+ url,
1391
+ get clientAddress() {
1392
+ if (clientAddressSymbol$1 in request) {
1393
+ return Reflect.get(request, clientAddressSymbol$1);
1394
+ }
1395
+ if (pipeline.adapterName) {
1396
+ throw new AstroError({
1397
+ ...ClientAddressNotAvailable,
1398
+ message: ClientAddressNotAvailable.message(pipeline.adapterName)
1541
1399
  });
1542
1400
  } else {
1543
- return await renderPage({
1544
- mod,
1545
- renderContext,
1546
- env,
1547
- cookies: apiContext.cookies
1548
- });
1401
+ throw new AstroError(StaticClientAddressNotAvailable);
1402
+ }
1403
+ },
1404
+ get locals() {
1405
+ return renderContext.locals;
1406
+ },
1407
+ // TODO(breaking): disallow replacing the locals object
1408
+ set locals(val) {
1409
+ if (typeof val !== "object") {
1410
+ throw new AstroError(LocalsNotAnObject);
1411
+ } else {
1412
+ renderContext.locals = val;
1413
+ Reflect.set(request, clientLocalsSymbol, val);
1549
1414
  }
1550
1415
  }
1551
- case "endpoint": {
1552
- return await callEndpoint(mod, env, renderContext, onRequest);
1553
- }
1554
- default:
1555
- throw new Error(`Couldn't find route of type [${renderContext.route.type}]`);
1556
- }
1416
+ };
1417
+ }
1418
+ async createResult(mod) {
1419
+ const { cookies, locals, params, pathname, pipeline, request, routeData, status } = this;
1420
+ const {
1421
+ adapterName,
1422
+ clientDirectives,
1423
+ compressHTML,
1424
+ i18n,
1425
+ manifest,
1426
+ logger,
1427
+ renderers,
1428
+ resolve,
1429
+ site,
1430
+ serverLike
1431
+ } = pipeline;
1432
+ const { links, scripts, styles } = await pipeline.headElements(routeData);
1433
+ const componentMetadata = await pipeline.componentMetadata(routeData) ?? manifest.componentMetadata;
1434
+ const { defaultLocale, locales, strategy } = i18n ?? {};
1435
+ const partial = Boolean(mod.partial);
1436
+ return createResult({
1437
+ adapterName,
1438
+ clientDirectives,
1439
+ componentMetadata,
1440
+ compressHTML,
1441
+ cookies,
1442
+ defaultLocale,
1443
+ locales,
1444
+ locals,
1445
+ logger,
1446
+ links,
1447
+ params,
1448
+ partial,
1449
+ pathname,
1450
+ renderers,
1451
+ resolve,
1452
+ request,
1453
+ route: routeData.route,
1454
+ strategy,
1455
+ site,
1456
+ scripts,
1457
+ ssr: serverLike,
1458
+ status,
1459
+ styles
1460
+ });
1557
1461
  }
1558
1462
  /**
1559
- * Store a function that will be called before starting the rendering phase.
1560
- * @param fn
1463
+ * API Context may be created multiple times per request, i18n data needs to be computed only once.
1464
+ * So, it is computed and saved here on creation of the first APIContext and reused for later ones.
1561
1465
  */
1562
- onBeforeRenderRoute(fn) {
1563
- this.#hooks.before.push(fn);
1466
+ #i18nData;
1467
+ get i18nData() {
1468
+ if (this.#i18nData)
1469
+ return this.#i18nData;
1470
+ const {
1471
+ pipeline: { i18n },
1472
+ request,
1473
+ routeData
1474
+ } = this;
1475
+ if (!i18n)
1476
+ return {
1477
+ currentLocale: void 0,
1478
+ preferredLocale: void 0,
1479
+ preferredLocaleList: void 0
1480
+ };
1481
+ const { defaultLocale, locales, strategy } = i18n;
1482
+ return this.#i18nData = {
1483
+ currentLocale: computeCurrentLocale(routeData.route, locales, strategy, defaultLocale),
1484
+ preferredLocale: computePreferredLocale(request, locales),
1485
+ preferredLocaleList: computePreferredLocaleList(request, locales)
1486
+ };
1564
1487
  }
1565
1488
  }
1566
1489
 
1567
- class SSRRoutePipeline extends Pipeline {
1568
- }
1569
-
1570
- const localsSymbol = Symbol.for("astro.locals");
1571
- const clientAddressSymbol$1 = Symbol.for("astro.clientAddress");
1572
- const responseSentSymbol = Symbol.for("astro.responseSent");
1573
- const REROUTABLE_STATUS_CODES = /* @__PURE__ */ new Set([404, 500]);
1574
1490
  class App {
1575
- /**
1576
- * The current environment of the application
1577
- */
1578
1491
  #manifest;
1579
1492
  #manifestData;
1580
- #routeDataToRouteInfo;
1581
1493
  #logger = new Logger({
1582
1494
  dest: consoleLogDestination,
1583
1495
  level: "info"
@@ -1591,9 +1503,8 @@ class App {
1591
1503
  this.#manifestData = {
1592
1504
  routes: manifest.routes.map((route) => route.routeData)
1593
1505
  };
1594
- this.#routeDataToRouteInfo = new Map(manifest.routes.map((route) => [route.routeData, route]));
1595
1506
  this.#baseWithoutTrailingSlash = removeTrailingForwardSlash(this.#manifest.base);
1596
- this.#pipeline = new SSRRoutePipeline(this.#createEnvironment(streaming));
1507
+ this.#pipeline = this.#createPipeline(streaming);
1597
1508
  this.#adapterLogger = new AstroIntegrationLogger(
1598
1509
  this.#logger.options,
1599
1510
  this.#manifest.adapterName
@@ -1603,19 +1514,17 @@ class App {
1603
1514
  return this.#adapterLogger;
1604
1515
  }
1605
1516
  /**
1606
- * Creates an environment by reading the stored manifest
1517
+ * Creates a pipeline by reading the stored manifest
1607
1518
  *
1608
1519
  * @param streaming
1609
1520
  * @private
1610
1521
  */
1611
- #createEnvironment(streaming = false) {
1612
- return createEnvironment({
1613
- adapterName: this.#manifest.adapterName,
1522
+ #createPipeline(streaming = false) {
1523
+ return AppPipeline.create({
1614
1524
  logger: this.#logger,
1525
+ manifest: this.#manifest,
1615
1526
  mode: "production",
1616
- compressHTML: this.#manifest.compressHTML,
1617
1527
  renderers: this.#manifest.renderers,
1618
- clientDirectives: this.#manifest.clientDirectives,
1619
1528
  resolve: async (specifier) => {
1620
1529
  if (!(specifier in this.#manifest.entryModules)) {
1621
1530
  throw new Error(`Unable to resolve [${specifier}]`);
@@ -1631,9 +1540,7 @@ class App {
1631
1540
  }
1632
1541
  }
1633
1542
  },
1634
- routeCache: new RouteCache(this.#logger),
1635
- site: this.#manifest.site,
1636
- ssr: true,
1543
+ serverLike: true,
1637
1544
  streaming
1638
1545
  });
1639
1546
  }
@@ -1667,7 +1574,7 @@ class App {
1667
1574
  #computePathnameFromDomain(request) {
1668
1575
  let pathname = void 0;
1669
1576
  const url = new URL(request.url);
1670
- if (this.#manifest.i18n && (this.#manifest.i18n.routing === "domains-prefix-always" || this.#manifest.i18n.routing === "domains-prefix-other-locales" || this.#manifest.i18n.routing === "domains-prefix-other-no-redirect")) {
1577
+ if (this.#manifest.i18n && (this.#manifest.i18n.strategy === "domains-prefix-always" || this.#manifest.i18n.strategy === "domains-prefix-other-locales" || this.#manifest.i18n.strategy === "domains-prefix-always-no-redirect")) {
1671
1578
  let host = request.headers.get("X-Forwarded-Host");
1672
1579
  let protocol = request.headers.get("X-Forwarded-Proto");
1673
1580
  if (protocol) {
@@ -1737,7 +1644,11 @@ class App {
1737
1644
  }
1738
1645
  }
1739
1646
  if (locals) {
1740
- Reflect.set(request, localsSymbol, locals);
1647
+ if (typeof locals !== "object") {
1648
+ this.#logger.error(null, new AstroError(LocalsNotAnObject).stack);
1649
+ return this.#renderError(request, { status: 500 });
1650
+ }
1651
+ Reflect.set(request, clientLocalsSymbol, locals);
1741
1652
  }
1742
1653
  if (clientAddress) {
1743
1654
  Reflect.set(request, clientAddressSymbol$1, clientAddress);
@@ -1754,35 +1665,22 @@ class App {
1754
1665
  const pathname = this.#getPathnameFromRequest(request);
1755
1666
  const defaultStatus = this.#getDefaultStatusCode(routeData, pathname);
1756
1667
  const mod = await this.#getModuleForRoute(routeData);
1757
- const pageModule = await mod.page();
1758
- const url = new URL(request.url);
1759
- const renderContext = await this.#createRenderContext(
1760
- url,
1761
- request,
1762
- routeData,
1763
- mod,
1764
- defaultStatus
1765
- );
1766
1668
  let response;
1767
1669
  try {
1768
- const i18nMiddleware = createI18nMiddleware(
1769
- this.#manifest.i18n,
1770
- this.#manifest.base,
1771
- this.#manifest.trailingSlash,
1772
- this.#manifest.buildFormat
1773
- );
1774
- if (i18nMiddleware) {
1775
- this.#pipeline.setMiddlewareFunction(sequence(i18nMiddleware, this.#manifest.middleware));
1776
- this.#pipeline.onBeforeRenderRoute(i18nPipelineHook);
1777
- } else {
1778
- this.#pipeline.setMiddlewareFunction(this.#manifest.middleware);
1779
- }
1780
- response = await this.#pipeline.renderRoute(renderContext, pageModule);
1670
+ const renderContext = RenderContext.create({
1671
+ pipeline: this.#pipeline,
1672
+ locals,
1673
+ pathname,
1674
+ request,
1675
+ routeData,
1676
+ status: defaultStatus
1677
+ });
1678
+ response = await renderContext.render(await mod.page());
1781
1679
  } catch (err) {
1782
1680
  this.#logger.error(null, err.stack || err.message || String(err));
1783
1681
  return this.#renderError(request, { status: 500 });
1784
1682
  }
1785
- if (REROUTABLE_STATUS_CODES.has(response.status) && response.headers.get(REROUTE_DIRECTIVE_HEADER) !== "no") {
1683
+ if (REROUTABLE_STATUS_CODES.includes(response.status) && response.headers.get(REROUTE_DIRECTIVE_HEADER) !== "no") {
1786
1684
  return this.#renderError(request, {
1787
1685
  response,
1788
1686
  status: response.status
@@ -1796,7 +1694,7 @@ class App {
1796
1694
  response.headers.append("set-cookie", setCookieHeaderValue);
1797
1695
  }
1798
1696
  }
1799
- Reflect.set(response, responseSentSymbol, true);
1697
+ Reflect.set(response, responseSentSymbol$1, true);
1800
1698
  return response;
1801
1699
  }
1802
1700
  #logRenderOptionsDeprecationWarning() {
@@ -1823,61 +1721,6 @@ class App {
1823
1721
  * @returns An iterator that yields key-value pairs as equal-sign-separated strings.
1824
1722
  */
1825
1723
  static getSetCookieFromResponse = getSetCookiesFromResponse;
1826
- /**
1827
- * Creates the render context of the current route
1828
- */
1829
- async #createRenderContext(url, request, routeData, page, status = 200) {
1830
- if (routeData.type === "endpoint") {
1831
- const pathname = "/" + this.removeBase(url.pathname);
1832
- const mod = await page.page();
1833
- const handler = mod;
1834
- return await createRenderContext({
1835
- request,
1836
- pathname,
1837
- route: routeData,
1838
- status,
1839
- env: this.#pipeline.env,
1840
- mod: handler,
1841
- locales: this.#manifest.i18n?.locales,
1842
- routing: this.#manifest.i18n?.routing,
1843
- defaultLocale: this.#manifest.i18n?.defaultLocale
1844
- });
1845
- } else {
1846
- const pathname = prependForwardSlash$1(this.removeBase(url.pathname));
1847
- const info = this.#routeDataToRouteInfo.get(routeData);
1848
- const links = /* @__PURE__ */ new Set();
1849
- const styles = createStylesheetElementSet(info.styles);
1850
- let scripts = /* @__PURE__ */ new Set();
1851
- for (const script of info.scripts) {
1852
- if ("stage" in script) {
1853
- if (script.stage === "head-inline") {
1854
- scripts.add({
1855
- props: {},
1856
- children: script.children
1857
- });
1858
- }
1859
- } else {
1860
- scripts.add(createModuleScriptElement(script));
1861
- }
1862
- }
1863
- const mod = await page.page();
1864
- return await createRenderContext({
1865
- request,
1866
- pathname,
1867
- componentMetadata: this.#manifest.componentMetadata,
1868
- scripts,
1869
- styles,
1870
- links,
1871
- route: routeData,
1872
- status,
1873
- mod,
1874
- env: this.#pipeline.env,
1875
- locales: this.#manifest.i18n?.locales,
1876
- routing: this.#manifest.i18n?.routing,
1877
- defaultLocale: this.#manifest.i18n?.defaultLocale
1878
- });
1879
- }
1880
- }
1881
1724
  /**
1882
1725
  * If it is a known error code, try sending the according page (e.g. 404.astro / 500.astro).
1883
1726
  * This also handles pre-rendered /404 or /500 routes
@@ -1899,21 +1742,15 @@ class App {
1899
1742
  }
1900
1743
  const mod = await this.#getModuleForRoute(errorRouteData);
1901
1744
  try {
1902
- const newRenderContext = await this.#createRenderContext(
1903
- url,
1745
+ const renderContext = RenderContext.create({
1746
+ pipeline: this.#pipeline,
1747
+ middleware: skipMiddleware ? (_, next) => next() : void 0,
1748
+ pathname: this.#getPathnameFromRequest(request),
1904
1749
  request,
1905
- errorRouteData,
1906
- mod,
1750
+ routeData: errorRouteData,
1907
1751
  status
1908
- );
1909
- const page = await mod.page();
1910
- if (skipMiddleware === false) {
1911
- this.#pipeline.setMiddlewareFunction(this.#manifest.middleware);
1912
- }
1913
- if (skipMiddleware) {
1914
- this.#pipeline.unsetMiddlewareFunction();
1915
- }
1916
- const response2 = await this.#pipeline.renderRoute(newRenderContext, page);
1752
+ });
1753
+ const response2 = await renderContext.render(await mod.page());
1917
1754
  return this.#mergeResponses(response2, originalResponse);
1918
1755
  } catch {
1919
1756
  if (skipMiddleware === false) {
@@ -1926,7 +1763,7 @@ class App {
1926
1763
  }
1927
1764
  }
1928
1765
  const response = this.#mergeResponses(new Response(null, { status }), originalResponse);
1929
- Reflect.set(response, responseSentSymbol, true);
1766
+ Reflect.set(response, responseSentSymbol$1, true);
1930
1767
  return response;
1931
1768
  }
1932
1769
  #mergeResponses(newResponse, originalResponse, override) {
@@ -2436,19 +2273,21 @@ const serverEntrypointModule = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.de
2436
2273
  start
2437
2274
  }, Symbol.toStringTag, { value: 'Module' }));
2438
2275
 
2439
- const _page0 = () => import('./chunks/node_zqXXqc-u.mjs');
2440
- const _page1 = () => import('./chunks/~fallback_Wahcp9Wk.mjs');
2441
- const _page2 = () => import('./chunks/index__05fnqFh.mjs');
2442
- const _page3 = () => import('./chunks/account_vK6pmJlz.mjs');
2443
- const _page4 = () => import('./chunks/_page__qqIVxbal.mjs');
2444
- const _page5 = () => import('./chunks/_.._19fCuQdO.mjs');
2276
+ const _page0 = () => import('./chunks/node_C7sdLKL4.mjs');
2277
+ const _page1 = () => import('./chunks/~fallback_YpJa9BIL.mjs');
2278
+ const _page2 = () => import('./chunks/index_BTDpenpc.mjs');
2279
+ const _page3 = () => import('./chunks/account_CaTloREf.mjs');
2280
+ const _page4 = () => import('./chunks/index_D0q4ab_n.mjs');
2281
+ const _page5 = () => import('./chunks/_page__DU3kNewy.mjs');
2282
+ const _page6 = () => import('./chunks/_.._DORZHe_Z.mjs');
2445
2283
  const pageMap = new Map([
2446
- ["../../node_modules/.pnpm/astro@4.3.2_@types+node@18.19.14_typescript@5.2.2/node_modules/astro/dist/assets/endpoint/node.js", _page0],
2284
+ ["../../node_modules/.pnpm/astro@4.4.4_@types+node@18.19.18_typescript@5.2.2/node_modules/astro/dist/assets/endpoint/node.js", _page0],
2447
2285
  ["src/pages/~fallback.astro", _page1],
2448
- ["src/pages/app/index.astro", _page2],
2286
+ ["src/pages/admin/index.astro", _page2],
2449
2287
  ["src/pages/app/account.astro", _page3],
2450
- ["src/pages/blog/[page].astro", _page4],
2451
- ["src/pages/[...slug].astro", _page5]
2288
+ ["src/pages/app/index.astro", _page4],
2289
+ ["src/pages/blog/[page].astro", _page5],
2290
+ ["src/pages/[...slug].astro", _page6]
2452
2291
  ]);
2453
2292
 
2454
2293
  const _manifest = Object.assign(manifest, {