@patternfly/patternfly-doc-core 1.9.1 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/astro.config.mjs +3 -4
  2. package/cli/cli.ts +60 -19
  3. package/cli/convertToMDX.ts +77 -22
  4. package/dist/.assetsignore +2 -0
  5. package/dist/_astro/ClientRouter.astro_astro_type_script_index_0_lang.CtSceO8m.js +1 -0
  6. package/dist/{client/_astro/LiveExample.DZkxbJA_.js → _astro/LiveExample.DjPiO80i.js} +1 -1
  7. package/dist/_astro/client.DN8ES6L5.js +1 -0
  8. package/dist/_routes.json +20 -0
  9. package/dist/_worker.js/_@astrojs-ssr-adapter.mjs +2 -0
  10. package/dist/_worker.js/_astro-internal_middleware.mjs +21 -0
  11. package/dist/_worker.js/_noop-actions.mjs +4 -0
  12. package/dist/{server/chunks/AutoLinkHeader_C2GD0g-K.mjs → _worker.js/chunks/AutoLinkHeader_xh_mBOfs.mjs} +13 -14
  13. package/dist/{server/chunks/Button_BKhHR-ak.mjs → _worker.js/chunks/Button_ByndGYyw.mjs} +83 -13
  14. package/dist/{server/chunks/CSSTable_B8tlH3gz.mjs → _worker.js/chunks/CSSTable_DAbso55e.mjs} +3 -3
  15. package/dist/_worker.js/chunks/PropsTables_BZngJp47.mjs +6628 -0
  16. package/dist/_worker.js/chunks/_@astrojs-ssr-adapter_C9Nk07-M.mjs +1082 -0
  17. package/dist/_worker.js/chunks/angle-down-icon_yt3z9cvI.mjs +3686 -0
  18. package/dist/_worker.js/chunks/astro/server_BpfPtTmt.mjs +7278 -0
  19. package/dist/_worker.js/chunks/astro-designed-error-pages_4xWqsa9_.mjs +928 -0
  20. package/dist/_worker.js/chunks/cloudflare-kv-binding_DMly_2Gl.mjs +107 -0
  21. package/dist/_worker.js/chunks/index_Dc2aKkl4.mjs +57 -0
  22. package/dist/{server/chunks/_@astrojs-ssr-adapter_CbICuCdt.mjs → _worker.js/chunks/index_DlGha6WC.mjs} +1295 -1817
  23. package/dist/_worker.js/chunks/noop-middleware_Ct44Kk5Y.mjs +10 -0
  24. package/dist/_worker.js/chunks/parse_EttCPxrw.mjs +271 -0
  25. package/dist/{server/chunks/path_Cvt6sEOY.mjs → _worker.js/chunks/path_C-ZOwaTP.mjs} +2 -1
  26. package/dist/{server/entry.mjs → _worker.js/index.js} +12 -19
  27. package/dist/_worker.js/manifest_DcBPbZXQ.mjs +100 -0
  28. package/dist/_worker.js/pages/_image.astro.mjs +24 -0
  29. package/dist/_worker.js/pages/_section_/_page_/_---tab_.astro.mjs +1 -0
  30. package/dist/_worker.js/pages/index.astro.mjs +1 -0
  31. package/dist/{server → _worker.js}/pages/props.astro.mjs +3 -2
  32. package/dist/_worker.js/renderers.mjs +484 -0
  33. package/dist/cli/cli.js +46 -12
  34. package/dist/cli/convertToMDX.js +53 -16
  35. package/dist/components/accordion/index.html +60 -0
  36. package/dist/components/accordion/react/index.html +60 -0
  37. package/dist/components/all-components/index.html +47 -0
  38. package/dist/design-foundations/typography/index.html +198 -0
  39. package/dist/{client/design-foundations → design-foundations}/usage-and-behavior/index.html +4 -54
  40. package/dist/get-started/contribute/index.html +94 -0
  41. package/dist/index.html +43 -0
  42. package/package.json +12 -8
  43. package/public/.assetsignore +2 -0
  44. package/src/components/LiveExample.astro +2 -2
  45. package/src/components/LiveExample.tsx +38 -9
  46. package/src/pages/props.ts +2 -2
  47. package/wrangler.jsonc +14 -0
  48. package/dist/client/_astro/ClientRouter.astro_astro_type_script_index_0_lang.Cainpjm5.js +0 -1
  49. package/dist/client/_astro/client.zs76E0tG.js +0 -1
  50. package/dist/client/components/accordion/index.html +0 -110
  51. package/dist/client/components/accordion/react/index.html +0 -110
  52. package/dist/client/components/all-components/index.html +0 -97
  53. package/dist/client/design-foundations/typography/index.html +0 -248
  54. package/dist/client/get-started/contribute/index.html +0 -144
  55. package/dist/client/index.html +0 -43
  56. package/dist/server/_@astrojs-ssr-adapter.mjs +0 -1
  57. package/dist/server/_noop-middleware.mjs +0 -3
  58. package/dist/server/chunks/PropsTables_PVzRHJNB.mjs +0 -1750
  59. package/dist/server/chunks/_astro_assets_DaYumpRZ.mjs +0 -1507
  60. package/dist/server/chunks/angle-down-icon_BO1Ed-9Z.mjs +0 -3288
  61. package/dist/server/chunks/astro/server_Cl9jPh4p.mjs +0 -2859
  62. package/dist/server/chunks/astro-designed-error-pages_BFveJFnQ.mjs +0 -282
  63. package/dist/server/chunks/consts_BmVDRGlB.mjs +0 -32
  64. package/dist/server/chunks/sharp_CbOL3WDk.mjs +0 -88
  65. package/dist/server/manifest_DxJLmW-j.mjs +0 -102
  66. package/dist/server/pages/_image.astro.mjs +0 -132
  67. package/dist/server/renderers.mjs +0 -308
  68. /package/dist/{client/PF-HorizontalLogo-Color.svg → PF-HorizontalLogo-Color.svg} +0 -0
  69. /package/dist/{client/PF-HorizontalLogo-Reverse.svg → PF-HorizontalLogo-Reverse.svg} +0 -0
  70. /package/dist/{client/_astro → _astro}/Button.BQCwQ5pE.js +0 -0
  71. /package/dist/{client/_astro → _astro}/CSSTable.DC79W1Ct.js +0 -0
  72. /package/dist/{client/_astro → _astro}/Content.B4M2qzJY.js +0 -0
  73. /package/dist/{client/_astro → _astro}/DropdownList.cxp03sS4.js +0 -0
  74. /package/dist/{client/_astro → _astro}/LiveExample.CxJsMvEq.css +0 -0
  75. /package/dist/{client/_astro → _astro}/Navigation.kbLxctIo.js +0 -0
  76. /package/dist/{client/_astro → _astro}/PageContext.miTsIqVo.js +0 -0
  77. /package/dist/{client/_astro → _astro}/PageSidebarBody.B0AJe8Hg.js +0 -0
  78. /package/dist/{client/_astro → _astro}/PageToggle.CMZ3C1v1.js +0 -0
  79. /package/dist/{client/_astro → _astro}/RedHatDisplayVF-Italic.CRpusWc8.woff2 +0 -0
  80. /package/dist/{client/_astro → _astro}/RedHatDisplayVF.CYDHf1NI.woff2 +0 -0
  81. /package/dist/{client/_astro → _astro}/RedHatMonoVF-Italic.DGQo2ogW.woff2 +0 -0
  82. /package/dist/{client/_astro → _astro}/RedHatMonoVF.C4fMH6Vz.woff2 +0 -0
  83. /package/dist/{client/_astro → _astro}/RedHatTextVF-Italic.Dkj_WqbA.woff2 +0 -0
  84. /package/dist/{client/_astro → _astro}/RedHatTextVF.wYvZ7prR.woff2 +0 -0
  85. /package/dist/{client/_astro → _astro}/SearchInput.DhHo7yPx.js +0 -0
  86. /package/dist/{client/_astro → _astro}/SectionGallery.3ABpQwE4.js +0 -0
  87. /package/dist/{client/_astro → _astro}/Toolbar.CroDQcyv.js +0 -0
  88. /package/dist/{client/_astro → _astro}/ToolbarContent.UH3ZRlHp.js +0 -0
  89. /package/dist/{client/_astro → _astro}/_page_.Chv_bGyU.css +0 -0
  90. /package/dist/{client/_astro → _astro}/_page_.CtheD08_.css +0 -0
  91. /package/dist/{client/_astro → _astro}/_page_.D1z73Byz.css +0 -0
  92. /package/dist/{client/_astro → _astro}/_page_.DxJDkZPc.css +0 -0
  93. /package/dist/{client/_astro → _astro}/angle-left-icon.teo8GC0v.js +0 -0
  94. /package/dist/{client/_astro → _astro}/bars-icon.Dk6ua1rr.js +0 -0
  95. /package/dist/{client/_astro → _astro}/divider.tlrBPkzg.js +0 -0
  96. /package/dist/{client/_astro → _astro}/fa-solid-900.DguXoeIz.woff2 +0 -0
  97. /package/dist/{client/_astro → _astro}/github-icon.ByC5XEPt.js +0 -0
  98. /package/dist/{client/_astro → _astro}/index.BQFV5hT1.js +0 -0
  99. /package/dist/{client/_astro → _astro}/index.CAChmxYj.js +0 -0
  100. /package/dist/{client/_astro → _astro}/index.DYVB4vTo.js +0 -0
  101. /package/dist/{client/_astro → _astro}/index.eCxJ45ll.js +0 -0
  102. /package/dist/{client/_astro → _astro}/link-icon.BNHnRn73.js +0 -0
  103. /package/dist/{client/_astro → _astro}/page.BTC3Kf3x.js +0 -0
  104. /package/dist/{client/_astro → _astro}/pf-v6-pficon.Dy6oiu9u.woff2 +0 -0
  105. /package/dist/{server/chunks/Accordion_BJka4Qvb.mjs → _worker.js/chunks/Accordion_BNafbla6.mjs} +0 -0
  106. /package/dist/{server/chunks/Accordion_BQIphkaZ.mjs → _worker.js/chunks/Accordion_CZsuyu9E.mjs} +0 -0
  107. /package/dist/{server/chunks/AllComponents_CRhgTsiT.mjs → _worker.js/chunks/AllComponents_BrL9IHSc.mjs} +0 -0
  108. /package/dist/{server/chunks/AllComponents_CjOtwUH6.mjs → _worker.js/chunks/AllComponents_CI7S6uwA.mjs} +0 -0
  109. /package/dist/{server/chunks/_astro_data-layer-content_D4Ib_RjR.mjs → _worker.js/chunks/_astro_assets_vBCb4v6U.mjs} +0 -0
  110. /package/dist/{server/chunks/content-assets_DleWbedO.mjs → _worker.js/chunks/_astro_data-layer-content_CgXoS6Mm.mjs} +0 -0
  111. /package/dist/{server/chunks/content-modules_fX1c2JRG.mjs → _worker.js/chunks/content-assets_XqCgPAV2.mjs} +0 -0
  112. /package/dist/{server/pages/_section_/_---page_.astro.mjs → _worker.js/chunks/content-modules_CKq2j9RQ.mjs} +0 -0
  113. /package/dist/{server/pages/_section_/_page_/_---tab_.astro.mjs → _worker.js/chunks/sharp_CNjr3bU4.mjs} +0 -0
  114. /package/dist/{server/pages/index.astro.mjs → _worker.js/pages/_section_/_---page_.astro.mjs} +0 -0
  115. /package/dist/{client/avatarImg.svg → avatarImg.svg} +0 -0
  116. /package/dist/{client/avatarImgDark.svg → avatarImgDark.svg} +0 -0
  117. /package/dist/{client/content → content}/typography/line-height.png +0 -0
  118. /package/dist/{client/favicon.svg → favicon.svg} +0 -0
@@ -0,0 +1,1082 @@
1
+ globalThis.process ??= {}; globalThis.process.env ??= {};
2
+ import 'cloudflare:workers';
3
+ import { f as fileExtension, j as joinPaths, s as slash, p as prependForwardSlash, a as removeTrailingForwardSlash, b as appendForwardSlash, c as collapseDuplicateTrailingSlashes, h as hasFileExtension } from './path_C-ZOwaTP.mjs';
4
+ import { r as requestIs404Or500, i as isRequestServerIsland, n as notFound, a as redirectToFallback, b as redirectToDefaultLocale, c as requestHasLocale, d as normalizeTheLocale, e as defineMiddleware, S as SERVER_ISLAND_COMPONENT, f as SERVER_ISLAND_ROUTE, g as createEndpoint, R as RouteCache, s as sequence, h as findRouteToRewrite, m as matchRoute, j as RenderContext, P as PERSIST_SYMBOL, k as getSetCookiesFromResponse } from './index_DlGha6WC.mjs';
5
+ import { w as ROUTE_TYPE_HEADER, x as REROUTE_DIRECTIVE_HEADER, D as DEFAULT_404_COMPONENT, A as AstroError, y as ActionNotFoundError, z as bold, B as red, C as yellow, E as dim, F as blue, G as clientAddressSymbol, L as LocalsNotAnObject, H as REROUTABLE_STATUS_CODES, I as responseSentSymbol } from './astro/server_BpfPtTmt.mjs';
6
+ import { D as DEFAULT_404_ROUTE, d as default404Instance, e as ensure404Route } from './astro-designed-error-pages_4xWqsa9_.mjs';
7
+ import { N as NOOP_MIDDLEWARE_FN } from './noop-middleware_Ct44Kk5Y.mjs';
8
+
9
+ function createI18nMiddleware(i18n, base, trailingSlash, format) {
10
+ if (!i18n) return (_, next) => next();
11
+ const payload = {
12
+ ...i18n,
13
+ trailingSlash,
14
+ base,
15
+ format};
16
+ const _redirectToDefaultLocale = redirectToDefaultLocale(payload);
17
+ const _noFoundForNonLocaleRoute = notFound(payload);
18
+ const _requestHasLocale = requestHasLocale(payload.locales);
19
+ const _redirectToFallback = redirectToFallback(payload);
20
+ const prefixAlways = (context, response) => {
21
+ const url = context.url;
22
+ if (url.pathname === base + "/" || url.pathname === base) {
23
+ return _redirectToDefaultLocale(context);
24
+ } else if (!_requestHasLocale(context)) {
25
+ return _noFoundForNonLocaleRoute(context, response);
26
+ }
27
+ return void 0;
28
+ };
29
+ const prefixOtherLocales = (context, response) => {
30
+ let pathnameContainsDefaultLocale = false;
31
+ const url = context.url;
32
+ for (const segment of url.pathname.split("/")) {
33
+ if (normalizeTheLocale(segment) === normalizeTheLocale(i18n.defaultLocale)) {
34
+ pathnameContainsDefaultLocale = true;
35
+ break;
36
+ }
37
+ }
38
+ if (pathnameContainsDefaultLocale) {
39
+ const newLocation = url.pathname.replace(`/${i18n.defaultLocale}`, "");
40
+ response.headers.set("Location", newLocation);
41
+ return _noFoundForNonLocaleRoute(context);
42
+ }
43
+ return void 0;
44
+ };
45
+ return async (context, next) => {
46
+ const response = await next();
47
+ const type = response.headers.get(ROUTE_TYPE_HEADER);
48
+ const isReroute = response.headers.get(REROUTE_DIRECTIVE_HEADER);
49
+ if (isReroute === "no" && typeof i18n.fallback === "undefined") {
50
+ return response;
51
+ }
52
+ if (type !== "page" && type !== "fallback") {
53
+ return response;
54
+ }
55
+ if (requestIs404Or500(context.request, base)) {
56
+ return response;
57
+ }
58
+ if (isRequestServerIsland(context.request, base)) {
59
+ return response;
60
+ }
61
+ const { currentLocale } = context;
62
+ switch (i18n.strategy) {
63
+ // NOTE: theoretically, we should never hit this code path
64
+ case "manual": {
65
+ return response;
66
+ }
67
+ case "domains-prefix-other-locales": {
68
+ if (localeHasntDomain(i18n, currentLocale)) {
69
+ const result = prefixOtherLocales(context, response);
70
+ if (result) {
71
+ return result;
72
+ }
73
+ }
74
+ break;
75
+ }
76
+ case "pathname-prefix-other-locales": {
77
+ const result = prefixOtherLocales(context, response);
78
+ if (result) {
79
+ return result;
80
+ }
81
+ break;
82
+ }
83
+ case "domains-prefix-always-no-redirect": {
84
+ if (localeHasntDomain(i18n, currentLocale)) {
85
+ const result = _noFoundForNonLocaleRoute(context, response);
86
+ if (result) {
87
+ return result;
88
+ }
89
+ }
90
+ break;
91
+ }
92
+ case "pathname-prefix-always-no-redirect": {
93
+ const result = _noFoundForNonLocaleRoute(context, response);
94
+ if (result) {
95
+ return result;
96
+ }
97
+ break;
98
+ }
99
+ case "pathname-prefix-always": {
100
+ const result = prefixAlways(context, response);
101
+ if (result) {
102
+ return result;
103
+ }
104
+ break;
105
+ }
106
+ case "domains-prefix-always": {
107
+ if (localeHasntDomain(i18n, currentLocale)) {
108
+ const result = prefixAlways(context, response);
109
+ if (result) {
110
+ return result;
111
+ }
112
+ }
113
+ break;
114
+ }
115
+ }
116
+ return _redirectToFallback(context, response);
117
+ };
118
+ }
119
+ function localeHasntDomain(i18n, currentLocale) {
120
+ for (const domainLocale of Object.values(i18n.domainLookupTable)) {
121
+ if (domainLocale === currentLocale) {
122
+ return false;
123
+ }
124
+ }
125
+ return true;
126
+ }
127
+
128
+ const NOOP_ACTIONS_MOD = {
129
+ server: {}
130
+ };
131
+
132
+ const FORM_CONTENT_TYPES = [
133
+ "application/x-www-form-urlencoded",
134
+ "multipart/form-data",
135
+ "text/plain"
136
+ ];
137
+ const SAFE_METHODS = ["GET", "HEAD", "OPTIONS"];
138
+ function createOriginCheckMiddleware() {
139
+ return defineMiddleware((context, next) => {
140
+ const { request, url, isPrerendered } = context;
141
+ if (isPrerendered) {
142
+ return next();
143
+ }
144
+ if (SAFE_METHODS.includes(request.method)) {
145
+ return next();
146
+ }
147
+ const isSameOrigin = request.headers.get("origin") === url.origin;
148
+ const hasContentType = request.headers.has("content-type");
149
+ if (hasContentType) {
150
+ const formLikeHeader = hasFormLikeHeader(request.headers.get("content-type"));
151
+ if (formLikeHeader && !isSameOrigin) {
152
+ return new Response(`Cross-site ${request.method} form submissions are forbidden`, {
153
+ status: 403
154
+ });
155
+ }
156
+ } else {
157
+ if (!isSameOrigin) {
158
+ return new Response(`Cross-site ${request.method} form submissions are forbidden`, {
159
+ status: 403
160
+ });
161
+ }
162
+ }
163
+ return next();
164
+ });
165
+ }
166
+ function hasFormLikeHeader(contentType) {
167
+ if (contentType) {
168
+ for (const FORM_CONTENT_TYPE of FORM_CONTENT_TYPES) {
169
+ if (contentType.toLowerCase().includes(FORM_CONTENT_TYPE)) {
170
+ return true;
171
+ }
172
+ }
173
+ }
174
+ return false;
175
+ }
176
+
177
+ function createDefaultRoutes(manifest) {
178
+ const root = new URL(manifest.hrefRoot);
179
+ return [
180
+ {
181
+ instance: default404Instance,
182
+ matchesComponent: (filePath) => filePath.href === new URL(DEFAULT_404_COMPONENT, root).href,
183
+ route: DEFAULT_404_ROUTE.route,
184
+ component: DEFAULT_404_COMPONENT
185
+ },
186
+ {
187
+ instance: createEndpoint(manifest),
188
+ matchesComponent: (filePath) => filePath.href === new URL(SERVER_ISLAND_COMPONENT, root).href,
189
+ route: SERVER_ISLAND_ROUTE,
190
+ component: SERVER_ISLAND_COMPONENT
191
+ }
192
+ ];
193
+ }
194
+
195
+ class Pipeline {
196
+ constructor(logger, manifest, runtimeMode, renderers, resolve, serverLike, streaming, adapterName = manifest.adapterName, clientDirectives = manifest.clientDirectives, inlinedScripts = manifest.inlinedScripts, compressHTML = manifest.compressHTML, i18n = manifest.i18n, middleware = manifest.middleware, routeCache = new RouteCache(logger, runtimeMode), site = manifest.site ? new URL(manifest.site) : void 0, defaultRoutes = createDefaultRoutes(manifest), actions = manifest.actions) {
197
+ this.logger = logger;
198
+ this.manifest = manifest;
199
+ this.runtimeMode = runtimeMode;
200
+ this.renderers = renderers;
201
+ this.resolve = resolve;
202
+ this.serverLike = serverLike;
203
+ this.streaming = streaming;
204
+ this.adapterName = adapterName;
205
+ this.clientDirectives = clientDirectives;
206
+ this.inlinedScripts = inlinedScripts;
207
+ this.compressHTML = compressHTML;
208
+ this.i18n = i18n;
209
+ this.middleware = middleware;
210
+ this.routeCache = routeCache;
211
+ this.site = site;
212
+ this.defaultRoutes = defaultRoutes;
213
+ this.actions = actions;
214
+ this.internalMiddleware = [];
215
+ if (i18n?.strategy !== "manual") {
216
+ this.internalMiddleware.push(
217
+ createI18nMiddleware(i18n, manifest.base, manifest.trailingSlash, manifest.buildFormat)
218
+ );
219
+ }
220
+ }
221
+ internalMiddleware;
222
+ resolvedMiddleware = void 0;
223
+ resolvedActions = void 0;
224
+ /**
225
+ * Resolves the middleware from the manifest, and returns the `onRequest` function. If `onRequest` isn't there,
226
+ * it returns a no-op function
227
+ */
228
+ async getMiddleware() {
229
+ if (this.resolvedMiddleware) {
230
+ return this.resolvedMiddleware;
231
+ } else if (this.middleware) {
232
+ const middlewareInstance = await this.middleware();
233
+ const onRequest = middlewareInstance.onRequest ?? NOOP_MIDDLEWARE_FN;
234
+ const internalMiddlewares = [onRequest];
235
+ if (this.manifest.checkOrigin) {
236
+ internalMiddlewares.unshift(createOriginCheckMiddleware());
237
+ }
238
+ this.resolvedMiddleware = sequence(...internalMiddlewares);
239
+ return this.resolvedMiddleware;
240
+ } else {
241
+ this.resolvedMiddleware = NOOP_MIDDLEWARE_FN;
242
+ return this.resolvedMiddleware;
243
+ }
244
+ }
245
+ setActions(actions) {
246
+ this.resolvedActions = actions;
247
+ }
248
+ async getActions() {
249
+ if (this.resolvedActions) {
250
+ return this.resolvedActions;
251
+ } else if (this.actions) {
252
+ return await this.actions();
253
+ }
254
+ return NOOP_ACTIONS_MOD;
255
+ }
256
+ async getAction(path) {
257
+ const pathKeys = path.split(".").map((key) => decodeURIComponent(key));
258
+ let { server } = await this.getActions();
259
+ if (!server || !(typeof server === "object")) {
260
+ throw new TypeError(
261
+ `Expected \`server\` export in actions file to be an object. Received ${typeof server}.`
262
+ );
263
+ }
264
+ for (const key of pathKeys) {
265
+ if (!(key in server)) {
266
+ throw new AstroError({
267
+ ...ActionNotFoundError,
268
+ message: ActionNotFoundError.message(pathKeys.join("."))
269
+ });
270
+ }
271
+ server = server[key];
272
+ }
273
+ if (typeof server !== "function") {
274
+ throw new TypeError(
275
+ `Expected handler for action ${pathKeys.join(".")} to be a function. Received ${typeof server}.`
276
+ );
277
+ }
278
+ return server;
279
+ }
280
+ }
281
+
282
+ const RedirectComponentInstance = {
283
+ default() {
284
+ return new Response(null, {
285
+ status: 301
286
+ });
287
+ }
288
+ };
289
+ const RedirectSinglePageBuiltModule = {
290
+ page: () => Promise.resolve(RedirectComponentInstance),
291
+ onRequest: (_, next) => next(),
292
+ renderers: []
293
+ };
294
+
295
+ const dateTimeFormat = new Intl.DateTimeFormat([], {
296
+ hour: "2-digit",
297
+ minute: "2-digit",
298
+ second: "2-digit",
299
+ hour12: false
300
+ });
301
+ const levels = {
302
+ debug: 20,
303
+ info: 30,
304
+ warn: 40,
305
+ error: 50,
306
+ silent: 90
307
+ };
308
+ function log(opts, level, label, message, newLine = true) {
309
+ const logLevel = opts.level;
310
+ const dest = opts.dest;
311
+ const event = {
312
+ label,
313
+ level,
314
+ message,
315
+ newLine
316
+ };
317
+ if (!isLogLevelEnabled(logLevel, level)) {
318
+ return;
319
+ }
320
+ dest.write(event);
321
+ }
322
+ function isLogLevelEnabled(configuredLogLevel, level) {
323
+ return levels[configuredLogLevel] <= levels[level];
324
+ }
325
+ function info(opts, label, message, newLine = true) {
326
+ return log(opts, "info", label, message, newLine);
327
+ }
328
+ function warn(opts, label, message, newLine = true) {
329
+ return log(opts, "warn", label, message, newLine);
330
+ }
331
+ function error(opts, label, message, newLine = true) {
332
+ return log(opts, "error", label, message, newLine);
333
+ }
334
+ function debug(...args) {
335
+ if ("_astroGlobalDebug" in globalThis) {
336
+ globalThis._astroGlobalDebug(...args);
337
+ }
338
+ }
339
+ function getEventPrefix({ level, label }) {
340
+ const timestamp = `${dateTimeFormat.format(/* @__PURE__ */ new Date())}`;
341
+ const prefix = [];
342
+ if (level === "error" || level === "warn") {
343
+ prefix.push(bold(timestamp));
344
+ prefix.push(`[${level.toUpperCase()}]`);
345
+ } else {
346
+ prefix.push(timestamp);
347
+ }
348
+ if (label) {
349
+ prefix.push(`[${label}]`);
350
+ }
351
+ if (level === "error") {
352
+ return red(prefix.join(" "));
353
+ }
354
+ if (level === "warn") {
355
+ return yellow(prefix.join(" "));
356
+ }
357
+ if (prefix.length === 1) {
358
+ return dim(prefix[0]);
359
+ }
360
+ return dim(prefix[0]) + " " + blue(prefix.splice(1).join(" "));
361
+ }
362
+ class Logger {
363
+ options;
364
+ constructor(options) {
365
+ this.options = options;
366
+ }
367
+ info(label, message, newLine = true) {
368
+ info(this.options, label, message, newLine);
369
+ }
370
+ warn(label, message, newLine = true) {
371
+ warn(this.options, label, message, newLine);
372
+ }
373
+ error(label, message, newLine = true) {
374
+ error(this.options, label, message, newLine);
375
+ }
376
+ debug(label, ...messages) {
377
+ debug(label, ...messages);
378
+ }
379
+ level() {
380
+ return this.options.level;
381
+ }
382
+ forkIntegrationLogger(label) {
383
+ return new AstroIntegrationLogger(this.options, label);
384
+ }
385
+ }
386
+ class AstroIntegrationLogger {
387
+ options;
388
+ label;
389
+ constructor(logging, label) {
390
+ this.options = logging;
391
+ this.label = label;
392
+ }
393
+ /**
394
+ * Creates a new logger instance with a new label, but the same log options.
395
+ */
396
+ fork(label) {
397
+ return new AstroIntegrationLogger(this.options, label);
398
+ }
399
+ info(message) {
400
+ info(this.options, this.label, message);
401
+ }
402
+ warn(message) {
403
+ warn(this.options, this.label, message);
404
+ }
405
+ error(message) {
406
+ error(this.options, this.label, message);
407
+ }
408
+ debug(message) {
409
+ debug(this.label, message);
410
+ }
411
+ }
412
+
413
+ const consoleLogDestination = {
414
+ write(event) {
415
+ let dest = console.error;
416
+ if (levels[event.level] < levels["error"]) {
417
+ dest = console.log;
418
+ }
419
+ if (event.label === "SKIP_FORMAT") {
420
+ dest(event.message);
421
+ } else {
422
+ dest(getEventPrefix(event) + " " + event.message);
423
+ }
424
+ return true;
425
+ }
426
+ };
427
+
428
+ function getAssetsPrefix(fileExtension, assetsPrefix) {
429
+ if (!assetsPrefix) return "";
430
+ if (typeof assetsPrefix === "string") return assetsPrefix;
431
+ const dotLessFileExtension = fileExtension.slice(1);
432
+ if (assetsPrefix[dotLessFileExtension]) {
433
+ return assetsPrefix[dotLessFileExtension];
434
+ }
435
+ return assetsPrefix.fallback;
436
+ }
437
+
438
+ function createAssetLink(href, base, assetsPrefix) {
439
+ if (assetsPrefix) {
440
+ const pf = getAssetsPrefix(fileExtension(href), assetsPrefix);
441
+ return joinPaths(pf, slash(href));
442
+ } else if (base) {
443
+ return prependForwardSlash(joinPaths(base, slash(href)));
444
+ } else {
445
+ return href;
446
+ }
447
+ }
448
+ function createStylesheetElement(stylesheet, base, assetsPrefix) {
449
+ if (stylesheet.type === "inline") {
450
+ return {
451
+ props: {},
452
+ children: stylesheet.content
453
+ };
454
+ } else {
455
+ return {
456
+ props: {
457
+ rel: "stylesheet",
458
+ href: createAssetLink(stylesheet.src, base, assetsPrefix)
459
+ },
460
+ children: ""
461
+ };
462
+ }
463
+ }
464
+ function createStylesheetElementSet(stylesheets, base, assetsPrefix) {
465
+ return new Set(stylesheets.map((s) => createStylesheetElement(s, base, assetsPrefix)));
466
+ }
467
+ function createModuleScriptElement(script, base, assetsPrefix) {
468
+ if (script.type === "external") {
469
+ return createModuleScriptElementWithSrc(script.value, base, assetsPrefix);
470
+ } else {
471
+ return {
472
+ props: {
473
+ type: "module"
474
+ },
475
+ children: script.value
476
+ };
477
+ }
478
+ }
479
+ function createModuleScriptElementWithSrc(src, base, assetsPrefix) {
480
+ return {
481
+ props: {
482
+ type: "module",
483
+ src: createAssetLink(src, base, assetsPrefix)
484
+ },
485
+ children: ""
486
+ };
487
+ }
488
+
489
+ function redirectTemplate({
490
+ status,
491
+ absoluteLocation,
492
+ relativeLocation,
493
+ from
494
+ }) {
495
+ const delay = status === 302 ? 2 : 0;
496
+ return `<!doctype html>
497
+ <title>Redirecting to: ${relativeLocation}</title>
498
+ <meta http-equiv="refresh" content="${delay};url=${relativeLocation}">
499
+ <meta name="robots" content="noindex">
500
+ <link rel="canonical" href="${absoluteLocation}">
501
+ <body>
502
+ <a href="${relativeLocation}">Redirecting ${from ? `from <code>${from}</code> ` : ""}to <code>${relativeLocation}</code></a>
503
+ </body>`;
504
+ }
505
+
506
+ class AppPipeline extends Pipeline {
507
+ static create({
508
+ logger,
509
+ manifest,
510
+ runtimeMode,
511
+ renderers,
512
+ resolve,
513
+ serverLike,
514
+ streaming,
515
+ defaultRoutes
516
+ }) {
517
+ const pipeline = new AppPipeline(
518
+ logger,
519
+ manifest,
520
+ runtimeMode,
521
+ renderers,
522
+ resolve,
523
+ serverLike,
524
+ streaming,
525
+ void 0,
526
+ void 0,
527
+ void 0,
528
+ void 0,
529
+ void 0,
530
+ void 0,
531
+ void 0,
532
+ void 0,
533
+ defaultRoutes
534
+ );
535
+ return pipeline;
536
+ }
537
+ headElements(routeData) {
538
+ const routeInfo = this.manifest.routes.find((route) => route.routeData === routeData);
539
+ const links = /* @__PURE__ */ new Set();
540
+ const scripts = /* @__PURE__ */ new Set();
541
+ const styles = createStylesheetElementSet(routeInfo?.styles ?? []);
542
+ for (const script of routeInfo?.scripts ?? []) {
543
+ if ("stage" in script) {
544
+ if (script.stage === "head-inline") {
545
+ scripts.add({
546
+ props: {},
547
+ children: script.children
548
+ });
549
+ }
550
+ } else {
551
+ scripts.add(createModuleScriptElement(script));
552
+ }
553
+ }
554
+ return { links, styles, scripts };
555
+ }
556
+ componentMetadata() {
557
+ }
558
+ async getComponentByRoute(routeData) {
559
+ const module = await this.getModuleForRoute(routeData);
560
+ return module.page();
561
+ }
562
+ async tryRewrite(payload, request) {
563
+ const { newUrl, pathname, routeData } = findRouteToRewrite({
564
+ payload,
565
+ request,
566
+ routes: this.manifest?.routes.map((r) => r.routeData),
567
+ trailingSlash: this.manifest.trailingSlash,
568
+ buildFormat: this.manifest.buildFormat,
569
+ base: this.manifest.base,
570
+ outDir: this.manifest.outDir
571
+ });
572
+ const componentInstance = await this.getComponentByRoute(routeData);
573
+ return { newUrl, pathname, componentInstance, routeData };
574
+ }
575
+ async getModuleForRoute(route) {
576
+ for (const defaultRoute of this.defaultRoutes) {
577
+ if (route.component === defaultRoute.component) {
578
+ return {
579
+ page: () => Promise.resolve(defaultRoute.instance),
580
+ renderers: []
581
+ };
582
+ }
583
+ }
584
+ if (route.type === "redirect") {
585
+ return RedirectSinglePageBuiltModule;
586
+ } else {
587
+ if (this.manifest.pageMap) {
588
+ const importComponentInstance = this.manifest.pageMap.get(route.component);
589
+ if (!importComponentInstance) {
590
+ throw new Error(
591
+ `Unexpectedly unable to find a component instance for route ${route.route}`
592
+ );
593
+ }
594
+ return await importComponentInstance();
595
+ } else if (this.manifest.pageModule) {
596
+ return this.manifest.pageModule;
597
+ }
598
+ throw new Error(
599
+ "Astro couldn't find the correct page to render, probably because it wasn't correctly mapped for SSR usage. This is an internal error, please file an issue."
600
+ );
601
+ }
602
+ }
603
+ }
604
+
605
+ class App {
606
+ #manifest;
607
+ #manifestData;
608
+ #logger = new Logger({
609
+ dest: consoleLogDestination,
610
+ level: "info"
611
+ });
612
+ #baseWithoutTrailingSlash;
613
+ #pipeline;
614
+ #adapterLogger;
615
+ constructor(manifest, streaming = true) {
616
+ this.#manifest = manifest;
617
+ this.#manifestData = {
618
+ routes: manifest.routes.map((route) => route.routeData)
619
+ };
620
+ ensure404Route(this.#manifestData);
621
+ this.#baseWithoutTrailingSlash = removeTrailingForwardSlash(this.#manifest.base);
622
+ this.#pipeline = this.#createPipeline(streaming);
623
+ this.#adapterLogger = new AstroIntegrationLogger(
624
+ this.#logger.options,
625
+ this.#manifest.adapterName
626
+ );
627
+ }
628
+ getAdapterLogger() {
629
+ return this.#adapterLogger;
630
+ }
631
+ /**
632
+ * Creates a pipeline by reading the stored manifest
633
+ *
634
+ * @param streaming
635
+ * @private
636
+ */
637
+ #createPipeline(streaming = false) {
638
+ return AppPipeline.create({
639
+ logger: this.#logger,
640
+ manifest: this.#manifest,
641
+ runtimeMode: "production",
642
+ renderers: this.#manifest.renderers,
643
+ defaultRoutes: createDefaultRoutes(this.#manifest),
644
+ resolve: async (specifier) => {
645
+ if (!(specifier in this.#manifest.entryModules)) {
646
+ throw new Error(`Unable to resolve [${specifier}]`);
647
+ }
648
+ const bundlePath = this.#manifest.entryModules[specifier];
649
+ if (bundlePath.startsWith("data:") || bundlePath.length === 0) {
650
+ return bundlePath;
651
+ } else {
652
+ return createAssetLink(bundlePath, this.#manifest.base, this.#manifest.assetsPrefix);
653
+ }
654
+ },
655
+ serverLike: true,
656
+ streaming
657
+ });
658
+ }
659
+ set setManifestData(newManifestData) {
660
+ this.#manifestData = newManifestData;
661
+ }
662
+ removeBase(pathname) {
663
+ if (pathname.startsWith(this.#manifest.base)) {
664
+ return pathname.slice(this.#baseWithoutTrailingSlash.length + 1);
665
+ }
666
+ return pathname;
667
+ }
668
+ /**
669
+ * It removes the base from the request URL, prepends it with a forward slash and attempts to decoded it.
670
+ *
671
+ * If the decoding fails, it logs the error and return the pathname as is.
672
+ * @param request
673
+ * @private
674
+ */
675
+ #getPathnameFromRequest(request) {
676
+ const url = new URL(request.url);
677
+ const pathname = prependForwardSlash(this.removeBase(url.pathname));
678
+ try {
679
+ return decodeURI(pathname);
680
+ } catch (e) {
681
+ this.getAdapterLogger().error(e.toString());
682
+ return pathname;
683
+ }
684
+ }
685
+ match(request) {
686
+ const url = new URL(request.url);
687
+ if (this.#manifest.assets.has(url.pathname)) return void 0;
688
+ let pathname = this.#computePathnameFromDomain(request);
689
+ if (!pathname) {
690
+ pathname = prependForwardSlash(this.removeBase(url.pathname));
691
+ }
692
+ let routeData = matchRoute(decodeURI(pathname), this.#manifestData);
693
+ if (!routeData || routeData.prerender) return void 0;
694
+ return routeData;
695
+ }
696
+ #computePathnameFromDomain(request) {
697
+ let pathname = void 0;
698
+ const url = new URL(request.url);
699
+ 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")) {
700
+ let host = request.headers.get("X-Forwarded-Host");
701
+ let protocol = request.headers.get("X-Forwarded-Proto");
702
+ if (protocol) {
703
+ protocol = protocol + ":";
704
+ } else {
705
+ protocol = url.protocol;
706
+ }
707
+ if (!host) {
708
+ host = request.headers.get("Host");
709
+ }
710
+ if (host && protocol) {
711
+ host = host.split(":")[0];
712
+ try {
713
+ let locale;
714
+ const hostAsUrl = new URL(`${protocol}//${host}`);
715
+ for (const [domainKey, localeValue] of Object.entries(
716
+ this.#manifest.i18n.domainLookupTable
717
+ )) {
718
+ const domainKeyAsUrl = new URL(domainKey);
719
+ if (hostAsUrl.host === domainKeyAsUrl.host && hostAsUrl.protocol === domainKeyAsUrl.protocol) {
720
+ locale = localeValue;
721
+ break;
722
+ }
723
+ }
724
+ if (locale) {
725
+ pathname = prependForwardSlash(
726
+ joinPaths(normalizeTheLocale(locale), this.removeBase(url.pathname))
727
+ );
728
+ if (url.pathname.endsWith("/")) {
729
+ pathname = appendForwardSlash(pathname);
730
+ }
731
+ }
732
+ } catch (e) {
733
+ this.#logger.error(
734
+ "router",
735
+ `Astro tried to parse ${protocol}//${host} as an URL, but it threw a parsing error. Check the X-Forwarded-Host and X-Forwarded-Proto headers.`
736
+ );
737
+ this.#logger.error("router", `Error: ${e}`);
738
+ }
739
+ }
740
+ }
741
+ return pathname;
742
+ }
743
+ #redirectTrailingSlash(pathname) {
744
+ const { trailingSlash } = this.#manifest;
745
+ if (pathname === "/" || pathname.startsWith("/_")) {
746
+ return pathname;
747
+ }
748
+ const path = collapseDuplicateTrailingSlashes(pathname, trailingSlash !== "never");
749
+ if (path !== pathname) {
750
+ return path;
751
+ }
752
+ if (trailingSlash === "ignore") {
753
+ return pathname;
754
+ }
755
+ if (trailingSlash === "always" && !hasFileExtension(pathname)) {
756
+ return appendForwardSlash(pathname);
757
+ }
758
+ if (trailingSlash === "never") {
759
+ return removeTrailingForwardSlash(pathname);
760
+ }
761
+ return pathname;
762
+ }
763
+ async render(request, renderOptions) {
764
+ let routeData;
765
+ let locals;
766
+ let clientAddress;
767
+ let addCookieHeader;
768
+ const url = new URL(request.url);
769
+ const redirect = this.#redirectTrailingSlash(url.pathname);
770
+ const prerenderedErrorPageFetch = renderOptions?.prerenderedErrorPageFetch ?? fetch;
771
+ if (redirect !== url.pathname) {
772
+ const status = request.method === "GET" ? 301 : 308;
773
+ return new Response(
774
+ redirectTemplate({
775
+ status,
776
+ relativeLocation: url.pathname,
777
+ absoluteLocation: redirect,
778
+ from: request.url
779
+ }),
780
+ {
781
+ status,
782
+ headers: {
783
+ location: redirect + url.search
784
+ }
785
+ }
786
+ );
787
+ }
788
+ addCookieHeader = renderOptions?.addCookieHeader;
789
+ clientAddress = renderOptions?.clientAddress ?? Reflect.get(request, clientAddressSymbol);
790
+ routeData = renderOptions?.routeData;
791
+ locals = renderOptions?.locals;
792
+ if (routeData) {
793
+ this.#logger.debug(
794
+ "router",
795
+ "The adapter " + this.#manifest.adapterName + " provided a custom RouteData for ",
796
+ request.url
797
+ );
798
+ this.#logger.debug("router", "RouteData:\n" + routeData);
799
+ }
800
+ if (locals) {
801
+ if (typeof locals !== "object") {
802
+ const error = new AstroError(LocalsNotAnObject);
803
+ this.#logger.error(null, error.stack);
804
+ return this.#renderError(request, {
805
+ status: 500,
806
+ error,
807
+ clientAddress,
808
+ prerenderedErrorPageFetch
809
+ });
810
+ }
811
+ }
812
+ if (!routeData) {
813
+ routeData = this.match(request);
814
+ this.#logger.debug("router", "Astro matched the following route for " + request.url);
815
+ this.#logger.debug("router", "RouteData:\n" + routeData);
816
+ }
817
+ if (!routeData) {
818
+ routeData = this.#manifestData.routes.find(
819
+ (route) => route.component === "404.astro" || route.component === DEFAULT_404_COMPONENT
820
+ );
821
+ }
822
+ if (!routeData) {
823
+ this.#logger.debug("router", "Astro hasn't found routes that match " + request.url);
824
+ this.#logger.debug("router", "Here's the available routes:\n", this.#manifestData);
825
+ return this.#renderError(request, {
826
+ locals,
827
+ status: 404,
828
+ clientAddress,
829
+ prerenderedErrorPageFetch
830
+ });
831
+ }
832
+ const pathname = this.#getPathnameFromRequest(request);
833
+ const defaultStatus = this.#getDefaultStatusCode(routeData, pathname);
834
+ let response;
835
+ let session;
836
+ try {
837
+ const mod = await this.#pipeline.getModuleForRoute(routeData);
838
+ const renderContext = await RenderContext.create({
839
+ pipeline: this.#pipeline,
840
+ locals,
841
+ pathname,
842
+ request,
843
+ routeData,
844
+ status: defaultStatus,
845
+ clientAddress
846
+ });
847
+ session = renderContext.session;
848
+ response = await renderContext.render(await mod.page());
849
+ } catch (err) {
850
+ this.#logger.error(null, err.stack || err.message || String(err));
851
+ return this.#renderError(request, {
852
+ locals,
853
+ status: 500,
854
+ error: err,
855
+ clientAddress,
856
+ prerenderedErrorPageFetch
857
+ });
858
+ } finally {
859
+ await session?.[PERSIST_SYMBOL]();
860
+ }
861
+ if (REROUTABLE_STATUS_CODES.includes(response.status) && response.headers.get(REROUTE_DIRECTIVE_HEADER) !== "no") {
862
+ return this.#renderError(request, {
863
+ locals,
864
+ response,
865
+ status: response.status,
866
+ // We don't have an error to report here. Passing null means we pass nothing intentionally
867
+ // while undefined means there's no error
868
+ error: response.status === 500 ? null : void 0,
869
+ clientAddress,
870
+ prerenderedErrorPageFetch
871
+ });
872
+ }
873
+ if (response.headers.has(REROUTE_DIRECTIVE_HEADER)) {
874
+ response.headers.delete(REROUTE_DIRECTIVE_HEADER);
875
+ }
876
+ if (addCookieHeader) {
877
+ for (const setCookieHeaderValue of App.getSetCookieFromResponse(response)) {
878
+ response.headers.append("set-cookie", setCookieHeaderValue);
879
+ }
880
+ }
881
+ Reflect.set(response, responseSentSymbol, true);
882
+ return response;
883
+ }
884
+ setCookieHeaders(response) {
885
+ return getSetCookiesFromResponse(response);
886
+ }
887
+ /**
888
+ * Reads all the cookies written by `Astro.cookie.set()` onto the passed response.
889
+ * For example,
890
+ * ```ts
891
+ * for (const cookie_ of App.getSetCookieFromResponse(response)) {
892
+ * const cookie: string = cookie_
893
+ * }
894
+ * ```
895
+ * @param response The response to read cookies from.
896
+ * @returns An iterator that yields key-value pairs as equal-sign-separated strings.
897
+ */
898
+ static getSetCookieFromResponse = getSetCookiesFromResponse;
899
+ /**
900
+ * If it is a known error code, try sending the according page (e.g. 404.astro / 500.astro).
901
+ * This also handles pre-rendered /404 or /500 routes
902
+ */
903
+ async #renderError(request, {
904
+ locals,
905
+ status,
906
+ response: originalResponse,
907
+ skipMiddleware = false,
908
+ error,
909
+ clientAddress,
910
+ prerenderedErrorPageFetch
911
+ }) {
912
+ const errorRoutePath = `/${status}${this.#manifest.trailingSlash === "always" ? "/" : ""}`;
913
+ const errorRouteData = matchRoute(errorRoutePath, this.#manifestData);
914
+ const url = new URL(request.url);
915
+ if (errorRouteData) {
916
+ if (errorRouteData.prerender) {
917
+ const maybeDotHtml = errorRouteData.route.endsWith(`/${status}`) ? ".html" : "";
918
+ const statusURL = new URL(
919
+ `${this.#baseWithoutTrailingSlash}/${status}${maybeDotHtml}`,
920
+ url
921
+ );
922
+ if (statusURL.toString() !== request.url) {
923
+ const response2 = await prerenderedErrorPageFetch(statusURL.toString());
924
+ const override = { status, removeContentEncodingHeaders: true };
925
+ return this.#mergeResponses(response2, originalResponse, override);
926
+ }
927
+ }
928
+ const mod = await this.#pipeline.getModuleForRoute(errorRouteData);
929
+ let session;
930
+ try {
931
+ const renderContext = await RenderContext.create({
932
+ locals,
933
+ pipeline: this.#pipeline,
934
+ middleware: skipMiddleware ? NOOP_MIDDLEWARE_FN : void 0,
935
+ pathname: this.#getPathnameFromRequest(request),
936
+ request,
937
+ routeData: errorRouteData,
938
+ status,
939
+ props: { error },
940
+ clientAddress
941
+ });
942
+ session = renderContext.session;
943
+ const response2 = await renderContext.render(await mod.page());
944
+ return this.#mergeResponses(response2, originalResponse);
945
+ } catch {
946
+ if (skipMiddleware === false) {
947
+ return this.#renderError(request, {
948
+ locals,
949
+ status,
950
+ response: originalResponse,
951
+ skipMiddleware: true,
952
+ clientAddress,
953
+ prerenderedErrorPageFetch
954
+ });
955
+ }
956
+ } finally {
957
+ await session?.[PERSIST_SYMBOL]();
958
+ }
959
+ }
960
+ const response = this.#mergeResponses(new Response(null, { status }), originalResponse);
961
+ Reflect.set(response, responseSentSymbol, true);
962
+ return response;
963
+ }
964
+ #mergeResponses(newResponse, originalResponse, override) {
965
+ let newResponseHeaders = newResponse.headers;
966
+ if (override?.removeContentEncodingHeaders) {
967
+ newResponseHeaders = new Headers(newResponseHeaders);
968
+ newResponseHeaders.delete("Content-Encoding");
969
+ newResponseHeaders.delete("Content-Length");
970
+ }
971
+ if (!originalResponse) {
972
+ if (override !== void 0) {
973
+ return new Response(newResponse.body, {
974
+ status: override.status,
975
+ statusText: newResponse.statusText,
976
+ headers: newResponseHeaders
977
+ });
978
+ }
979
+ return newResponse;
980
+ }
981
+ const status = override?.status ? override.status : originalResponse.status === 200 ? newResponse.status : originalResponse.status;
982
+ try {
983
+ originalResponse.headers.delete("Content-type");
984
+ } catch {
985
+ }
986
+ const mergedHeaders = new Map([
987
+ ...Array.from(newResponseHeaders),
988
+ ...Array.from(originalResponse.headers)
989
+ ]);
990
+ const newHeaders = new Headers();
991
+ for (const [name, value] of mergedHeaders) {
992
+ newHeaders.set(name, value);
993
+ }
994
+ return new Response(newResponse.body, {
995
+ status,
996
+ statusText: status === 200 ? newResponse.statusText : originalResponse.statusText,
997
+ // If you're looking at here for possible bugs, it means that it's not a bug.
998
+ // With the middleware, users can meddle with headers, and we should pass to the 404/500.
999
+ // If users see something weird, it's because they are setting some headers they should not.
1000
+ //
1001
+ // Although, we don't want it to replace the content-type, because the error page must return `text/html`
1002
+ headers: newHeaders
1003
+ });
1004
+ }
1005
+ #getDefaultStatusCode(routeData, pathname) {
1006
+ if (!routeData.pattern.test(pathname)) {
1007
+ for (const fallbackRoute of routeData.fallbackRoutes) {
1008
+ if (fallbackRoute.pattern.test(pathname)) {
1009
+ return 302;
1010
+ }
1011
+ }
1012
+ }
1013
+ const route = removeTrailingForwardSlash(routeData.route);
1014
+ if (route.endsWith("/404")) return 404;
1015
+ if (route.endsWith("/500")) return 500;
1016
+ return 200;
1017
+ }
1018
+ }
1019
+
1020
+ function createExports(manifest) {
1021
+ const app = new App(manifest);
1022
+ const fetch = async (request, env, context) => {
1023
+ const { pathname } = new URL(request.url);
1024
+ const bindingName = "SESSION";
1025
+ globalThis.__env__ ??= {};
1026
+ globalThis.__env__[bindingName] = env[bindingName];
1027
+ if (manifest.assets.has(pathname)) {
1028
+ return env.ASSETS.fetch(request.url.replace(/\.html$/, ""));
1029
+ }
1030
+ const routeData = app.match(request);
1031
+ if (!routeData) {
1032
+ const asset = await env.ASSETS.fetch(
1033
+ request.url.replace(/index.html$/, "").replace(/\.html$/, "")
1034
+ );
1035
+ if (asset.status !== 404) {
1036
+ return asset;
1037
+ }
1038
+ }
1039
+ Reflect.set(
1040
+ request,
1041
+ Symbol.for("astro.clientAddress"),
1042
+ request.headers.get("cf-connecting-ip")
1043
+ );
1044
+ process.env.ASTRO_STUDIO_APP_TOKEN ??= (() => {
1045
+ if (typeof env.ASTRO_STUDIO_APP_TOKEN === "string") {
1046
+ return env.ASTRO_STUDIO_APP_TOKEN;
1047
+ }
1048
+ })();
1049
+ const locals = {
1050
+ runtime: {
1051
+ env,
1052
+ cf: request.cf,
1053
+ caches,
1054
+ ctx: {
1055
+ waitUntil: (promise) => context.waitUntil(promise),
1056
+ // Currently not available: https://developers.cloudflare.com/pages/platform/known-issues/#pages-functions
1057
+ passThroughOnException: () => {
1058
+ throw new Error(
1059
+ "`passThroughOnException` is currently not available in Cloudflare Pages. See https://developers.cloudflare.com/pages/platform/known-issues/#pages-functions."
1060
+ );
1061
+ },
1062
+ props: {}
1063
+ }
1064
+ }
1065
+ };
1066
+ const response = await app.render(request, { routeData, locals });
1067
+ if (app.setCookieHeaders) {
1068
+ for (const setCookieHeader of app.setCookieHeaders(response)) {
1069
+ response.headers.append("Set-Cookie", setCookieHeader);
1070
+ }
1071
+ }
1072
+ return response;
1073
+ };
1074
+ return { default: { fetch } };
1075
+ }
1076
+
1077
+ const serverEntrypointModule = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
1078
+ __proto__: null,
1079
+ createExports
1080
+ }, Symbol.toStringTag, { value: 'Module' }));
1081
+
1082
+ export { createExports as c, serverEntrypointModule as s };