cloudcommerce 0.37.1 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/test-apps.yml +2 -2
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +64 -0
- package/action.yml +2 -2
- package/ecomplus-stores/barra-doce/functions/many/package.json +3 -3
- package/ecomplus-stores/barra-doce/functions/ssr/package.json +6 -6
- package/ecomplus-stores/barra-doce/functions/ssr/src/layouts/PageHeader.astro +3 -6
- package/ecomplus-stores/barra-doce/functions/with-apps/package.json +3 -3
- package/ecomplus-stores/barra-doce/package.json +2 -2
- package/package.json +7 -7
- package/packages/api/lib/api.d.ts +2 -2
- package/packages/api/package.json +1 -1
- package/packages/api/types.d.ts +4 -1
- package/packages/apps/affilate-program/package.json +1 -1
- package/packages/apps/correios/package.json +1 -1
- package/packages/apps/custom-payment/package.json +1 -1
- package/packages/apps/custom-shipping/package.json +1 -1
- package/packages/apps/datafrete/package.json +1 -1
- package/packages/apps/discounts/package.json +1 -1
- package/packages/apps/emails/package.json +1 -1
- package/packages/apps/fb-conversions/package.json +1 -1
- package/packages/apps/flash-courier/package.json +1 -1
- package/packages/apps/frenet/package.json +1 -1
- package/packages/apps/galaxpay/package.json +1 -1
- package/packages/apps/google-analytics/package.json +1 -1
- package/packages/apps/jadlog/package.json +1 -1
- package/packages/apps/loyalty-points/package.json +1 -1
- package/packages/apps/mandae/package.json +1 -1
- package/packages/apps/melhor-envio/package.json +1 -1
- package/packages/apps/mercadopago/package.json +1 -1
- package/packages/apps/pagarme/package.json +1 -1
- package/packages/apps/pagarme-v5/package.json +1 -1
- package/packages/apps/paghiper/package.json +1 -1
- package/packages/apps/pix/package.json +1 -1
- package/packages/apps/tiny-erp/package.json +1 -1
- package/packages/apps/webhooks/package.json +1 -1
- package/packages/cli/config/firestore.rules +4 -1
- package/packages/cli/lib/cli.js +30 -9
- package/packages/cli/package.json +2 -1
- package/packages/cli/src/cli.ts +37 -9
- package/packages/config/package.json +1 -1
- package/packages/emails/package.json +1 -1
- package/packages/eslint/package.json +3 -3
- package/packages/events/package.json +1 -1
- package/packages/feeds/package.json +1 -1
- package/packages/firebase/package.json +1 -1
- package/packages/i18n/package.json +1 -1
- package/packages/modules/package.json +1 -1
- package/packages/passport/package.json +1 -1
- package/packages/ssr/package.json +5 -5
- package/packages/storefront/.auto-imports.d.ts +1 -0
- package/packages/storefront/client.d.ts +1 -0
- package/packages/storefront/config/storefront.tailwind.cjs +21 -20
- package/packages/storefront/config/storefront.unocss.cjs +11 -0
- package/packages/storefront/dist/client/_astro/{AccountPage.700be123.js → AccountPage.j0C5JBLY.js} +1 -1
- package/packages/storefront/dist/client/_astro/{CartSidebar.430b55df.js → CartSidebar.1kUFk9Xn.js} +1 -1
- package/packages/storefront/dist/client/_astro/HeroSlider.tR1dVXyu.js +1 -0
- package/packages/storefront/dist/client/_astro/{PitchBar.06e0f831.js → PitchBar.FelC04wE.js} +1 -1
- package/packages/storefront/dist/client/_astro/{Prices.0e829c31.js → Prices.PuQc6C7F.js} +1 -1
- package/packages/storefront/dist/client/_astro/ProductCard.ephJafAE.js +1 -0
- package/packages/storefront/dist/client/_astro/ProductDetails.B6Ih5MGf.js +7 -0
- package/packages/storefront/dist/client/_astro/ProductShelf.GESxuPZ_.js +1 -0
- package/packages/storefront/dist/client/_astro/{QuantitySelector.ebf60845.js → QuantitySelector.YNmWjN8y.js} +1 -1
- package/packages/storefront/dist/client/_astro/SearchContainer.BzixfU3R.js +1 -0
- package/packages/storefront/dist/client/_astro/SearchModal.F7vbwxIv.js +1 -0
- package/packages/storefront/dist/client/_astro/ShopHeader.5vR1LgSW.js +10 -0
- package/packages/storefront/dist/client/_astro/_plugin-vue_export-helper.sk5AFsEV.js +1 -0
- package/packages/storefront/dist/client/_astro/_slug_.r8QHNfdw.css +1 -0
- package/packages/storefront/dist/client/_astro/client.RF8UxjZd.js +1 -0
- package/packages/storefront/dist/client/_astro/customer-session._VkzXnXT.js +7 -0
- package/packages/storefront/dist/client/_astro/ecom-utils.gJYgRPRz.js +1 -0
- package/packages/storefront/dist/client/_astro/{firebase-app.992a296f.js → firebase-app.cPMfoOsn.js} +1 -1
- package/packages/storefront/dist/client/_astro/{format-money.9cf6b04d.js → format-money.FMQXgKHB.js} +1 -1
- package/packages/storefront/dist/client/_astro/{hoisted.c90fc6ab.js → hoisted.B6fKrLPR.js} +1 -1
- package/packages/storefront/dist/client/_astro/{hoisted.54eaab04.js → hoisted._FbzheVm.js} +1 -1
- package/packages/storefront/dist/client/_astro/{i18n.29216eeb.js → i18n.m7SpISxy.js} +1 -1
- package/packages/storefront/dist/client/_astro/{img.4f23a3dd.js → img.zh-Drf-O.js} +1 -1
- package/packages/storefront/dist/client/_astro/{index-61e5ac61.bdc8d0cd.js → index-dd468b12.D5s8VdAL.js} +92 -107
- package/packages/storefront/dist/client/_astro/{index.570b84fe.js → index.5PN-EYMS.js} +1 -1
- package/packages/storefront/dist/client/_astro/index.XrHFaN2F.js +1 -0
- package/packages/storefront/dist/client/_astro/{modules-info.55780599.js → modules-info.sD0tdb2b.js} +1 -1
- package/packages/storefront/dist/client/_astro/name.HU5l7TJo.js +1 -0
- package/packages/storefront/dist/client/_astro/{photoswipe-lightbox.esm.c157838f.js → photoswipe-lightbox.esm.dZBqKD9u.js} +1 -1
- package/packages/storefront/dist/client/_astro/{photoswipe.01431ec7.js → photoswipe.0V7m2jWu.js} +1 -2
- package/packages/storefront/dist/client/_astro/{photoswipe.esm.92c2d901.js → photoswipe.esm.Ylh9TGkz.js} +1 -1
- package/packages/storefront/dist/client/_astro/sf-utils.5t7r9A2G.js +1 -0
- package/packages/storefront/dist/client/_astro/{shopping-cart.d9f601dd.js → shopping-cart.A-1jhlKi.js} +1 -1
- package/packages/storefront/dist/client/_astro/use-analytics.1EVxbrS7.js +1 -0
- package/packages/storefront/dist/client/_astro/{use-product-card.437911bb.js → use-product-card.erbOV6Fv.js} +1 -1
- package/packages/storefront/dist/client/robots.txt +1 -0
- package/packages/storefront/dist/server/chunks/{CartSidebar_eab28771.mjs → CartSidebar_hAgJQJgm.mjs} +1 -1
- package/packages/storefront/dist/server/chunks/SearchModal_eWb5SdQM.mjs +351 -0
- package/packages/storefront/dist/server/chunks/{_.._5a781fb3.mjs → _.._S7DDBn_b.mjs} +1 -1
- package/packages/storefront/dist/server/chunks/{account_519edb70.mjs → account_3ySmGzMc.mjs} +1 -1
- package/packages/storefront/dist/server/chunks/astro/{assets-service_a9d9ab5f.mjs → assets-service_QlOZG8ov.mjs} +1 -1
- package/packages/storefront/dist/server/chunks/{astro_d98f7186.mjs → astro_zcC1GStV.mjs} +17 -34
- package/packages/storefront/dist/server/chunks/{index_5e3ed8a0.mjs → index_nIwq11oA.mjs} +1 -1
- package/packages/storefront/dist/server/chunks/{index_10e14f85.mjs → index_uAR5ZV4d.mjs} +1 -1
- package/packages/storefront/dist/server/chunks/{node_1119b0d1.mjs → node_2VvC7trl.mjs} +1 -1
- package/packages/storefront/dist/server/chunks/pages/{__93ade2dd.mjs → __MSibDuuV.mjs} +652 -255
- package/packages/storefront/dist/server/chunks/pages/{account_e5d410a7.mjs → account_iG-YqJ5q.mjs} +3 -2
- package/packages/storefront/dist/server/chunks/pages/{index_7e25afc1.mjs → index_BtDyKPh_.mjs} +3 -2
- package/packages/storefront/dist/server/chunks/pages/{node_bd378ac0.mjs → node_bKqL47eZ.mjs} +2 -2
- package/packages/storefront/dist/server/chunks/pages/{~fallback_73578d2f.mjs → ~fallback_73R5VA6j.mjs} +3 -2
- package/packages/storefront/dist/server/chunks/{photoswipe_9528923e.mjs → photoswipe_IcWDJiwc.mjs} +1 -1
- package/packages/storefront/dist/server/chunks/{~fallback_41122b9b.mjs → ~fallback_7q1dqY4e.mjs} +1 -1
- package/packages/storefront/dist/server/entry.mjs +970 -93
- package/packages/storefront/dist/server/manifest_dSwvaOdW.mjs +195 -0
- package/packages/storefront/dist/server/renderers.mjs +2 -2
- package/packages/storefront/package.json +12 -12
- package/packages/storefront/src/helpers/sf-utils.ts +29 -1
- package/packages/storefront/src/lib/components/SharedData.astro +2 -2
- package/packages/storefront/src/lib/composables/use-breadcrumbs.ts +1 -1
- package/packages/storefront/src/lib/composables/use-search-modal.ts +1 -1
- package/packages/storefront/src/lib/composables/use-search-showcase.ts +55 -0
- package/packages/storefront/src/lib/composables/use-shared-data.ts +10 -5
- package/packages/storefront/src/lib/composables/use-shop-header.ts +14 -5
- package/packages/storefront/src/lib/composables/use-sticky-header.ts +2 -0
- package/packages/storefront/src/lib/layouts/BaseHead.astro +8 -1
- package/packages/storefront/src/lib/layouts/use-page-header.ts +6 -3
- package/packages/storefront/src/lib/layouts/use-page-main.ts +45 -1
- package/packages/storefront/src/lib/scripts/firestore.ts +27 -0
- package/packages/storefront/src/lib/ssr-context.ts +14 -0
- package/packages/storefront/src/lib/state/search-engine.ts +65 -27
- package/packages/storefront/src/lib/state/use-analytics.ts +9 -10
- package/packages/test-base/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/storefront/dist/client/_astro/HeroSlider.bd684ed8.js +0 -1
- package/packages/storefront/dist/client/_astro/ProductDetails.06da998d.js +0 -1
- package/packages/storefront/dist/client/_astro/ProductShelf.3f4f38b5.js +0 -1
- package/packages/storefront/dist/client/_astro/ProductShelf.bf82838b.js +0 -1
- package/packages/storefront/dist/client/_astro/SearchModal.b6aa5ef7.js +0 -1
- package/packages/storefront/dist/client/_astro/ShopHeader.2d6e361a.js +0 -4
- package/packages/storefront/dist/client/_astro/_plugin-vue_export-helper.f75743ee.js +0 -1
- package/packages/storefront/dist/client/_astro/_slug_.e7cac999.css +0 -1
- package/packages/storefront/dist/client/_astro/client.41b42098.js +0 -1
- package/packages/storefront/dist/client/_astro/customer-session.5ab9ab1a.js +0 -1
- package/packages/storefront/dist/client/_astro/ecom-utils.5cbfb95e.js +0 -1
- package/packages/storefront/dist/client/_astro/index.8ac1db99.js +0 -1
- package/packages/storefront/dist/client/_astro/name.01410784.js +0 -1
- package/packages/storefront/dist/client/_astro/sf-utils.b04e1813.js +0 -1
- package/packages/storefront/dist/client/_astro/use-analytics.cc95e346.js +0 -1
- package/packages/storefront/dist/server/chunks/SearchModal_f66549d4.mjs +0 -147
- package/packages/storefront/dist/server/manifest_221d806b.mjs +0 -1069
- /package/packages/storefront/dist/client/_astro/{afetch.f4507208.js → afetch.5c8VmT0-.js} +0 -0
- /package/packages/storefront/dist/client/_astro/{img-sizes.41e0efe4.js → img-sizes.gxAI9JNh.js} +0 -0
- /package/packages/storefront/dist/client/_astro/{price.04ceb6c4.js → price.Easct8WC.js} +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import http from 'node:http';
|
|
3
3
|
import { TLSSocket } from 'node:tls';
|
|
4
|
-
import { appendForwardSlash as appendForwardSlash$1, joinPaths, slash, prependForwardSlash, removeTrailingForwardSlash, collapseDuplicateSlashes } from '@astrojs/internal-helpers/path';
|
|
5
|
-
import 'cookie';
|
|
6
|
-
import { l as levels,
|
|
7
|
-
import
|
|
8
|
-
import { A as AstroError, R as
|
|
4
|
+
import { appendForwardSlash as appendForwardSlash$1, joinPaths, trimSlashes, slash, prependForwardSlash, removeTrailingForwardSlash, collapseDuplicateSlashes } from '@astrojs/internal-helpers/path';
|
|
5
|
+
import { serialize, parse } from 'cookie';
|
|
6
|
+
import { l as levels, g as getEventPrefix, L as Logger, A as AstroIntegrationLogger, manifest } from './manifest_dSwvaOdW.mjs';
|
|
7
|
+
import 'kleur/colors';
|
|
8
|
+
import { A as AstroError, R as ResponseSentError, o as MiddlewareNoDataOrNextCalled, p as MiddlewareNotAResponse, G as GetStaticPathsRequired, q as InvalidGetStaticPathsReturn, t as InvalidGetStaticPathsEntry, v as GetStaticPathsExpectedParams, w as GetStaticPathsInvalidRouteParam, P as PageNumberParamNotFound, N as NoMatchingStaticPathFound, x as PrerenderDynamicEndpointPathCollide, y as LocalsNotAnObject, z as ASTRO_VERSION, C as ClientAddressNotAvailable, S as StaticClientAddressNotAvailable, B as renderEndpoint, D as ReservedSlotName, k as renderSlotToString, H as renderJSX, J as chunkToString, K as CantRenderPage, O as renderPage$1 } from './chunks/astro_zcC1GStV.mjs';
|
|
9
9
|
import 'clsx';
|
|
10
10
|
import buffer from 'node:buffer';
|
|
11
11
|
import crypto from 'node:crypto';
|
|
@@ -17,14 +17,53 @@ import send from 'send';
|
|
|
17
17
|
import enableDestroy from 'server-destroy';
|
|
18
18
|
import { renderers } from './renderers.mjs';
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
function getPathByLocale(locale, locales) {
|
|
21
|
+
for (const loopLocale of locales) {
|
|
22
|
+
if (typeof loopLocale === "string") {
|
|
23
|
+
if (loopLocale === locale) {
|
|
24
|
+
return loopLocale;
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
for (const code of loopLocale.codes) {
|
|
28
|
+
if (code === locale) {
|
|
29
|
+
return loopLocale.path;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function normalizeTheLocale(locale) {
|
|
36
|
+
return locale.replaceAll("_", "-").toLowerCase();
|
|
37
|
+
}
|
|
38
|
+
function toCodes(locales) {
|
|
39
|
+
const codes = [];
|
|
22
40
|
for (const locale of locales) {
|
|
23
|
-
if (
|
|
24
|
-
|
|
41
|
+
if (typeof locale === "string") {
|
|
42
|
+
codes.push(locale);
|
|
43
|
+
} else {
|
|
44
|
+
for (const code of locale.codes) {
|
|
45
|
+
codes.push(code);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return codes;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const routeDataSymbol = Symbol.for("astro.routeData");
|
|
53
|
+
function pathnameHasLocale(pathname, locales) {
|
|
54
|
+
const segments = pathname.split("/");
|
|
55
|
+
for (const segment of segments) {
|
|
56
|
+
for (const locale of locales) {
|
|
57
|
+
if (typeof locale === "string") {
|
|
58
|
+
if (normalizeTheLocale(segment) === normalizeTheLocale(locale)) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
} else if (segment === locale.path) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
25
64
|
}
|
|
26
65
|
}
|
|
27
|
-
return
|
|
66
|
+
return false;
|
|
28
67
|
}
|
|
29
68
|
function createI18nMiddleware(i18n, base, trailingSlash) {
|
|
30
69
|
if (!i18n) {
|
|
@@ -41,27 +80,25 @@ function createI18nMiddleware(i18n, base, trailingSlash) {
|
|
|
41
80
|
}
|
|
42
81
|
}
|
|
43
82
|
const url = context.url;
|
|
44
|
-
const { locales, defaultLocale, fallback } = i18n;
|
|
83
|
+
const { locales, defaultLocale, fallback, routing } = i18n;
|
|
45
84
|
const response = await next();
|
|
46
85
|
if (response instanceof Response) {
|
|
47
|
-
const separators = url.pathname.split("/");
|
|
48
86
|
const pathnameContainsDefaultLocale = url.pathname.includes(`/${defaultLocale}`);
|
|
49
|
-
|
|
50
|
-
if (i18n.routingStrategy === "prefix-other-locales" && pathnameContainsDefaultLocale) {
|
|
87
|
+
if (i18n.routing === "prefix-other-locales" && pathnameContainsDefaultLocale) {
|
|
51
88
|
const newLocation = url.pathname.replace(`/${defaultLocale}`, "");
|
|
52
89
|
response.headers.set("Location", newLocation);
|
|
53
90
|
return new Response(null, {
|
|
54
91
|
status: 404,
|
|
55
92
|
headers: response.headers
|
|
56
93
|
});
|
|
57
|
-
} else if (i18n.
|
|
94
|
+
} else if (i18n.routing === "prefix-always") {
|
|
58
95
|
if (url.pathname === base + "/" || url.pathname === base) {
|
|
59
96
|
if (trailingSlash === "always") {
|
|
60
97
|
return context.redirect(`${appendForwardSlash$1(joinPaths(base, i18n.defaultLocale))}`);
|
|
61
98
|
} else {
|
|
62
99
|
return context.redirect(`${joinPaths(base, i18n.defaultLocale)}`);
|
|
63
100
|
}
|
|
64
|
-
} else if (
|
|
101
|
+
} else if (!pathnameHasLocale(url.pathname, i18n.locales)) {
|
|
65
102
|
return new Response(null, {
|
|
66
103
|
status: 404,
|
|
67
104
|
headers: response.headers
|
|
@@ -70,14 +107,27 @@ function createI18nMiddleware(i18n, base, trailingSlash) {
|
|
|
70
107
|
}
|
|
71
108
|
if (response.status >= 300 && fallback) {
|
|
72
109
|
const fallbackKeys = i18n.fallback ? Object.keys(i18n.fallback) : [];
|
|
73
|
-
const
|
|
110
|
+
const segments = url.pathname.split("/");
|
|
111
|
+
const urlLocale = segments.find((segment) => {
|
|
112
|
+
for (const locale of locales) {
|
|
113
|
+
if (typeof locale === "string") {
|
|
114
|
+
if (locale === segment) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
} else if (locale.path === segment) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
});
|
|
74
123
|
if (urlLocale && fallbackKeys.includes(urlLocale)) {
|
|
75
124
|
const fallbackLocale = fallback[urlLocale];
|
|
125
|
+
const pathFallbackLocale = getPathByLocale(fallbackLocale, locales);
|
|
76
126
|
let newPathname;
|
|
77
|
-
if (
|
|
127
|
+
if (pathFallbackLocale === defaultLocale && routing === "prefix-other-locales") {
|
|
78
128
|
newPathname = url.pathname.replace(`/${urlLocale}`, ``);
|
|
79
129
|
} else {
|
|
80
|
-
newPathname = url.pathname.replace(`/${urlLocale}`, `/${
|
|
130
|
+
newPathname = url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`);
|
|
81
131
|
}
|
|
82
132
|
return context.redirect(newPathname);
|
|
83
133
|
}
|
|
@@ -90,44 +140,278 @@ const i18nPipelineHook = (ctx) => {
|
|
|
90
140
|
Reflect.set(ctx.request, routeDataSymbol, ctx.route);
|
|
91
141
|
};
|
|
92
142
|
|
|
93
|
-
|
|
94
|
-
|
|
143
|
+
const DELETED_EXPIRATION = /* @__PURE__ */ new Date(0);
|
|
144
|
+
const DELETED_VALUE = "deleted";
|
|
145
|
+
const responseSentSymbol$2 = Symbol.for("astro.responseSent");
|
|
146
|
+
class AstroCookie {
|
|
147
|
+
constructor(value) {
|
|
148
|
+
this.value = value;
|
|
149
|
+
}
|
|
150
|
+
json() {
|
|
151
|
+
if (this.value === void 0) {
|
|
152
|
+
throw new Error(`Cannot convert undefined to an object.`);
|
|
153
|
+
}
|
|
154
|
+
return JSON.parse(this.value);
|
|
155
|
+
}
|
|
156
|
+
number() {
|
|
157
|
+
return Number(this.value);
|
|
158
|
+
}
|
|
159
|
+
boolean() {
|
|
160
|
+
if (this.value === "false")
|
|
161
|
+
return false;
|
|
162
|
+
if (this.value === "0")
|
|
163
|
+
return false;
|
|
164
|
+
return Boolean(this.value);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
class AstroCookies {
|
|
168
|
+
#request;
|
|
169
|
+
#requestValues;
|
|
170
|
+
#outgoing;
|
|
171
|
+
constructor(request) {
|
|
172
|
+
this.#request = request;
|
|
173
|
+
this.#requestValues = null;
|
|
174
|
+
this.#outgoing = null;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Astro.cookies.delete(key) is used to delete a cookie. Using this method will result
|
|
178
|
+
* in a Set-Cookie header added to the response.
|
|
179
|
+
* @param key The cookie to delete
|
|
180
|
+
* @param options Options related to this deletion, such as the path of the cookie.
|
|
181
|
+
*/
|
|
182
|
+
delete(key, options) {
|
|
183
|
+
const serializeOptions = {
|
|
184
|
+
expires: DELETED_EXPIRATION
|
|
185
|
+
};
|
|
186
|
+
if (options?.domain) {
|
|
187
|
+
serializeOptions.domain = options.domain;
|
|
188
|
+
}
|
|
189
|
+
if (options?.path) {
|
|
190
|
+
serializeOptions.path = options.path;
|
|
191
|
+
}
|
|
192
|
+
this.#ensureOutgoingMap().set(key, [
|
|
193
|
+
DELETED_VALUE,
|
|
194
|
+
serialize(key, DELETED_VALUE, serializeOptions),
|
|
195
|
+
false
|
|
196
|
+
]);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Astro.cookies.get(key) is used to get a cookie value. The cookie value is read from the
|
|
200
|
+
* request. If you have set a cookie via Astro.cookies.set(key, value), the value will be taken
|
|
201
|
+
* from that set call, overriding any values already part of the request.
|
|
202
|
+
* @param key The cookie to get.
|
|
203
|
+
* @returns An object containing the cookie value as well as convenience methods for converting its value.
|
|
204
|
+
*/
|
|
205
|
+
get(key) {
|
|
206
|
+
if (this.#outgoing?.has(key)) {
|
|
207
|
+
let [serializedValue, , isSetValue] = this.#outgoing.get(key);
|
|
208
|
+
if (isSetValue) {
|
|
209
|
+
return new AstroCookie(serializedValue);
|
|
210
|
+
} else {
|
|
211
|
+
return void 0;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const values = this.#ensureParsed();
|
|
215
|
+
if (key in values) {
|
|
216
|
+
const value = values[key];
|
|
217
|
+
return new AstroCookie(value);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Astro.cookies.has(key) returns a boolean indicating whether this cookie is either
|
|
222
|
+
* part of the initial request or set via Astro.cookies.set(key)
|
|
223
|
+
* @param key The cookie to check for.
|
|
224
|
+
* @returns
|
|
225
|
+
*/
|
|
226
|
+
has(key) {
|
|
227
|
+
if (this.#outgoing?.has(key)) {
|
|
228
|
+
let [, , isSetValue] = this.#outgoing.get(key);
|
|
229
|
+
return isSetValue;
|
|
230
|
+
}
|
|
231
|
+
const values = this.#ensureParsed();
|
|
232
|
+
return !!values[key];
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Astro.cookies.set(key, value) is used to set a cookie's value. If provided
|
|
236
|
+
* an object it will be stringified via JSON.stringify(value). Additionally you
|
|
237
|
+
* can provide options customizing how this cookie will be set, such as setting httpOnly
|
|
238
|
+
* in order to prevent the cookie from being read in client-side JavaScript.
|
|
239
|
+
* @param key The name of the cookie to set.
|
|
240
|
+
* @param value A value, either a string or other primitive or an object.
|
|
241
|
+
* @param options Options for the cookie, such as the path and security settings.
|
|
242
|
+
*/
|
|
243
|
+
set(key, value, options) {
|
|
244
|
+
let serializedValue;
|
|
245
|
+
if (typeof value === "string") {
|
|
246
|
+
serializedValue = value;
|
|
247
|
+
} else {
|
|
248
|
+
let toStringValue = value.toString();
|
|
249
|
+
if (toStringValue === Object.prototype.toString.call(value)) {
|
|
250
|
+
serializedValue = JSON.stringify(value);
|
|
251
|
+
} else {
|
|
252
|
+
serializedValue = toStringValue;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
const serializeOptions = {};
|
|
256
|
+
if (options) {
|
|
257
|
+
Object.assign(serializeOptions, options);
|
|
258
|
+
}
|
|
259
|
+
this.#ensureOutgoingMap().set(key, [
|
|
260
|
+
serializedValue,
|
|
261
|
+
serialize(key, serializedValue, serializeOptions),
|
|
262
|
+
true
|
|
263
|
+
]);
|
|
264
|
+
if (this.#request[responseSentSymbol$2]) {
|
|
265
|
+
throw new AstroError({
|
|
266
|
+
...ResponseSentError
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Astro.cookies.header() returns an iterator for the cookies that have previously
|
|
272
|
+
* been set by either Astro.cookies.set() or Astro.cookies.delete().
|
|
273
|
+
* This method is primarily used by adapters to set the header on outgoing responses.
|
|
274
|
+
* @returns
|
|
275
|
+
*/
|
|
276
|
+
*headers() {
|
|
277
|
+
if (this.#outgoing == null)
|
|
278
|
+
return;
|
|
279
|
+
for (const [, value] of this.#outgoing) {
|
|
280
|
+
yield value[1];
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
#ensureParsed() {
|
|
284
|
+
if (!this.#requestValues) {
|
|
285
|
+
this.#parse();
|
|
286
|
+
}
|
|
287
|
+
if (!this.#requestValues) {
|
|
288
|
+
this.#requestValues = {};
|
|
289
|
+
}
|
|
290
|
+
return this.#requestValues;
|
|
291
|
+
}
|
|
292
|
+
#ensureOutgoingMap() {
|
|
293
|
+
if (!this.#outgoing) {
|
|
294
|
+
this.#outgoing = /* @__PURE__ */ new Map();
|
|
295
|
+
}
|
|
296
|
+
return this.#outgoing;
|
|
297
|
+
}
|
|
298
|
+
#parse() {
|
|
299
|
+
const raw = this.#request.headers.get("cookie");
|
|
300
|
+
if (!raw) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
this.#requestValues = parse(raw);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const astroCookiesSymbol = Symbol.for("astro.cookies");
|
|
308
|
+
function attachCookiesToResponse(response, cookies) {
|
|
309
|
+
Reflect.set(response, astroCookiesSymbol, cookies);
|
|
310
|
+
}
|
|
311
|
+
function responseHasCookies(response) {
|
|
312
|
+
return Reflect.has(response, astroCookiesSymbol);
|
|
313
|
+
}
|
|
314
|
+
function getFromResponse(response) {
|
|
315
|
+
let cookies = Reflect.get(response, astroCookiesSymbol);
|
|
316
|
+
if (cookies != null) {
|
|
317
|
+
return cookies;
|
|
318
|
+
} else {
|
|
319
|
+
return void 0;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function* getSetCookiesFromResponse(response) {
|
|
323
|
+
const cookies = getFromResponse(response);
|
|
324
|
+
if (!cookies) {
|
|
325
|
+
return [];
|
|
326
|
+
}
|
|
327
|
+
for (const headerValue of cookies.headers()) {
|
|
328
|
+
yield headerValue;
|
|
329
|
+
}
|
|
330
|
+
return [];
|
|
331
|
+
}
|
|
332
|
+
|
|
95
333
|
const consoleLogDestination = {
|
|
96
334
|
write(event) {
|
|
97
335
|
let dest = console.error;
|
|
98
336
|
if (levels[event.level] < levels["error"]) {
|
|
99
337
|
dest = console.log;
|
|
100
338
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
let type = event.label;
|
|
104
|
-
if (type) {
|
|
105
|
-
prefix += dim(dateTimeFormat.format(/* @__PURE__ */ new Date()) + " ");
|
|
106
|
-
if (event.level === "info") {
|
|
107
|
-
type = bold(cyan(`[${type}]`));
|
|
108
|
-
} else if (event.level === "warn") {
|
|
109
|
-
type = bold(yellow(`[${type}]`));
|
|
110
|
-
} else if (event.level === "error") {
|
|
111
|
-
type = bold(red(`[${type}]`));
|
|
112
|
-
}
|
|
113
|
-
prefix += `${type} `;
|
|
114
|
-
}
|
|
115
|
-
return reset(prefix);
|
|
116
|
-
}
|
|
117
|
-
let message = event.message;
|
|
118
|
-
if (message === lastMessage) {
|
|
119
|
-
lastMessageCount++;
|
|
120
|
-
message = `${message} ${yellow(`(x${lastMessageCount})`)}`;
|
|
339
|
+
if (event.label === "SKIP_FORMAT") {
|
|
340
|
+
dest(event.message);
|
|
121
341
|
} else {
|
|
122
|
-
|
|
123
|
-
lastMessageCount = 1;
|
|
342
|
+
dest(getEventPrefix(event) + " " + event.message);
|
|
124
343
|
}
|
|
125
|
-
const outMessage = getPrefix() + message;
|
|
126
|
-
dest(outMessage);
|
|
127
344
|
return true;
|
|
128
345
|
}
|
|
129
346
|
};
|
|
130
347
|
|
|
348
|
+
async function callMiddleware(onRequest, apiContext, responseFunction) {
|
|
349
|
+
let nextCalled = false;
|
|
350
|
+
let responseFunctionPromise = void 0;
|
|
351
|
+
const next = async () => {
|
|
352
|
+
nextCalled = true;
|
|
353
|
+
responseFunctionPromise = responseFunction();
|
|
354
|
+
return responseFunctionPromise;
|
|
355
|
+
};
|
|
356
|
+
let middlewarePromise = onRequest(apiContext, next);
|
|
357
|
+
return await Promise.resolve(middlewarePromise).then(async (value) => {
|
|
358
|
+
if (nextCalled) {
|
|
359
|
+
if (typeof value !== "undefined") {
|
|
360
|
+
if (value instanceof Response === false) {
|
|
361
|
+
throw new AstroError(MiddlewareNotAResponse);
|
|
362
|
+
}
|
|
363
|
+
return ensureCookiesAttached(apiContext, value);
|
|
364
|
+
} else {
|
|
365
|
+
if (responseFunctionPromise) {
|
|
366
|
+
return responseFunctionPromise;
|
|
367
|
+
} else {
|
|
368
|
+
throw new AstroError(MiddlewareNotAResponse);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
} else if (typeof value === "undefined") {
|
|
372
|
+
throw new AstroError(MiddlewareNoDataOrNextCalled);
|
|
373
|
+
} else if (value instanceof Response === false) {
|
|
374
|
+
throw new AstroError(MiddlewareNotAResponse);
|
|
375
|
+
} else {
|
|
376
|
+
return ensureCookiesAttached(apiContext, value);
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
function ensureCookiesAttached(apiContext, response) {
|
|
381
|
+
if (apiContext.cookies !== void 0 && !responseHasCookies(response)) {
|
|
382
|
+
attachCookiesToResponse(response, apiContext.cookies);
|
|
383
|
+
}
|
|
384
|
+
return response;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function routeIsRedirect(route) {
|
|
388
|
+
return route?.type === "redirect";
|
|
389
|
+
}
|
|
390
|
+
function routeIsFallback(route) {
|
|
391
|
+
return route?.type === "fallback";
|
|
392
|
+
}
|
|
393
|
+
function redirectRouteGenerate(redirectRoute, data) {
|
|
394
|
+
const routeData = redirectRoute.redirectRoute;
|
|
395
|
+
const route = redirectRoute.redirect;
|
|
396
|
+
if (typeof routeData !== "undefined") {
|
|
397
|
+
return routeData?.generate(data) || routeData?.pathname || "/";
|
|
398
|
+
} else if (typeof route === "string") {
|
|
399
|
+
return route;
|
|
400
|
+
} else if (typeof route === "undefined") {
|
|
401
|
+
return "/";
|
|
402
|
+
}
|
|
403
|
+
return route.destination;
|
|
404
|
+
}
|
|
405
|
+
function redirectRouteStatus(redirectRoute, method = "GET") {
|
|
406
|
+
const routeData = redirectRoute.redirectRoute;
|
|
407
|
+
if (typeof routeData?.redirect === "object") {
|
|
408
|
+
return routeData.redirect.status;
|
|
409
|
+
} else if (method !== "GET") {
|
|
410
|
+
return 308;
|
|
411
|
+
}
|
|
412
|
+
return 301;
|
|
413
|
+
}
|
|
414
|
+
|
|
131
415
|
const RedirectComponentInstance = {
|
|
132
416
|
default() {
|
|
133
417
|
return new Response(null, {
|
|
@@ -141,10 +425,578 @@ const RedirectSinglePageBuiltModule = {
|
|
|
141
425
|
renderers: []
|
|
142
426
|
};
|
|
143
427
|
|
|
428
|
+
const VALID_PARAM_TYPES = ["string", "number", "undefined"];
|
|
429
|
+
function validateGetStaticPathsParameter([key, value], route) {
|
|
430
|
+
if (!VALID_PARAM_TYPES.includes(typeof value)) {
|
|
431
|
+
throw new AstroError({
|
|
432
|
+
...GetStaticPathsInvalidRouteParam,
|
|
433
|
+
message: GetStaticPathsInvalidRouteParam.message(key, value, typeof value),
|
|
434
|
+
location: {
|
|
435
|
+
file: route
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
function validateDynamicRouteModule(mod, {
|
|
441
|
+
ssr,
|
|
442
|
+
route
|
|
443
|
+
}) {
|
|
444
|
+
if ((!ssr || route.prerender) && !mod.getStaticPaths) {
|
|
445
|
+
throw new AstroError({
|
|
446
|
+
...GetStaticPathsRequired,
|
|
447
|
+
location: { file: route.component }
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function validateGetStaticPathsResult(result, logger, route) {
|
|
452
|
+
if (!Array.isArray(result)) {
|
|
453
|
+
throw new AstroError({
|
|
454
|
+
...InvalidGetStaticPathsReturn,
|
|
455
|
+
message: InvalidGetStaticPathsReturn.message(typeof result),
|
|
456
|
+
location: {
|
|
457
|
+
file: route.component
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
result.forEach((pathObject) => {
|
|
462
|
+
if (typeof pathObject === "object" && Array.isArray(pathObject) || pathObject === null) {
|
|
463
|
+
throw new AstroError({
|
|
464
|
+
...InvalidGetStaticPathsEntry,
|
|
465
|
+
message: InvalidGetStaticPathsEntry.message(
|
|
466
|
+
Array.isArray(pathObject) ? "array" : typeof pathObject
|
|
467
|
+
)
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
if (pathObject.params === void 0 || pathObject.params === null || pathObject.params && Object.keys(pathObject.params).length === 0) {
|
|
471
|
+
throw new AstroError({
|
|
472
|
+
...GetStaticPathsExpectedParams,
|
|
473
|
+
location: {
|
|
474
|
+
file: route.component
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
for (const [key, val] of Object.entries(pathObject.params)) {
|
|
479
|
+
if (!(typeof val === "undefined" || typeof val === "string" || typeof val === "number")) {
|
|
480
|
+
logger.warn(
|
|
481
|
+
"router",
|
|
482
|
+
`getStaticPaths() returned an invalid path param: "${key}". A string, number or undefined value was expected, but got \`${JSON.stringify(
|
|
483
|
+
val
|
|
484
|
+
)}\`.`
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
if (typeof val === "string" && val === "") {
|
|
488
|
+
logger.warn(
|
|
489
|
+
"router",
|
|
490
|
+
`getStaticPaths() returned an invalid path param: "${key}". \`undefined\` expected for an optional param, but got empty string.`
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function getParams(array) {
|
|
498
|
+
const fn = (match) => {
|
|
499
|
+
const params = {};
|
|
500
|
+
array.forEach((key, i) => {
|
|
501
|
+
if (key.startsWith("...")) {
|
|
502
|
+
params[key.slice(3)] = match[i + 1] ? decodeURIComponent(match[i + 1]) : void 0;
|
|
503
|
+
} else {
|
|
504
|
+
params[key] = decodeURIComponent(match[i + 1]);
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
return params;
|
|
508
|
+
};
|
|
509
|
+
return fn;
|
|
510
|
+
}
|
|
511
|
+
function stringifyParams(params, route) {
|
|
512
|
+
const validatedParams = Object.entries(params).reduce((acc, next) => {
|
|
513
|
+
validateGetStaticPathsParameter(next, route.component);
|
|
514
|
+
const [key, value] = next;
|
|
515
|
+
if (value !== void 0) {
|
|
516
|
+
acc[key] = typeof value === "string" ? trimSlashes(value) : value.toString();
|
|
517
|
+
}
|
|
518
|
+
return acc;
|
|
519
|
+
}, {});
|
|
520
|
+
return JSON.stringify(route.generate(validatedParams));
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function generatePaginateFunction(routeMatch) {
|
|
524
|
+
return function paginateUtility(data, args = {}) {
|
|
525
|
+
let { pageSize: _pageSize, params: _params, props: _props } = args;
|
|
526
|
+
const pageSize = _pageSize || 10;
|
|
527
|
+
const paramName = "page";
|
|
528
|
+
const additionalParams = _params || {};
|
|
529
|
+
const additionalProps = _props || {};
|
|
530
|
+
let includesFirstPageNumber;
|
|
531
|
+
if (routeMatch.params.includes(`...${paramName}`)) {
|
|
532
|
+
includesFirstPageNumber = false;
|
|
533
|
+
} else if (routeMatch.params.includes(`${paramName}`)) {
|
|
534
|
+
includesFirstPageNumber = true;
|
|
535
|
+
} else {
|
|
536
|
+
throw new AstroError({
|
|
537
|
+
...PageNumberParamNotFound,
|
|
538
|
+
message: PageNumberParamNotFound.message(paramName)
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
const lastPage = Math.max(1, Math.ceil(data.length / pageSize));
|
|
542
|
+
const result = [...Array(lastPage).keys()].map((num) => {
|
|
543
|
+
const pageNum = num + 1;
|
|
544
|
+
const start = pageSize === Infinity ? 0 : (pageNum - 1) * pageSize;
|
|
545
|
+
const end = Math.min(start + pageSize, data.length);
|
|
546
|
+
const params = {
|
|
547
|
+
...additionalParams,
|
|
548
|
+
[paramName]: includesFirstPageNumber || pageNum > 1 ? String(pageNum) : void 0
|
|
549
|
+
};
|
|
550
|
+
const current = correctIndexRoute(routeMatch.generate({ ...params }));
|
|
551
|
+
const next = pageNum === lastPage ? void 0 : correctIndexRoute(routeMatch.generate({ ...params, page: String(pageNum + 1) }));
|
|
552
|
+
const prev = pageNum === 1 ? void 0 : correctIndexRoute(
|
|
553
|
+
routeMatch.generate({
|
|
554
|
+
...params,
|
|
555
|
+
page: !includesFirstPageNumber && pageNum - 1 === 1 ? void 0 : String(pageNum - 1)
|
|
556
|
+
})
|
|
557
|
+
);
|
|
558
|
+
return {
|
|
559
|
+
params,
|
|
560
|
+
props: {
|
|
561
|
+
...additionalProps,
|
|
562
|
+
page: {
|
|
563
|
+
data: data.slice(start, end),
|
|
564
|
+
start,
|
|
565
|
+
end: end - 1,
|
|
566
|
+
size: pageSize,
|
|
567
|
+
total: data.length,
|
|
568
|
+
currentPage: pageNum,
|
|
569
|
+
lastPage,
|
|
570
|
+
url: { current, next, prev }
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
});
|
|
575
|
+
return result;
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
function correctIndexRoute(route) {
|
|
579
|
+
if (route === "") {
|
|
580
|
+
return "/";
|
|
581
|
+
}
|
|
582
|
+
return route;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
async function callGetStaticPaths({
|
|
586
|
+
mod,
|
|
587
|
+
route,
|
|
588
|
+
routeCache,
|
|
589
|
+
logger,
|
|
590
|
+
ssr
|
|
591
|
+
}) {
|
|
592
|
+
const cached = routeCache.get(route);
|
|
593
|
+
if (!mod) {
|
|
594
|
+
throw new Error("This is an error caused by Astro and not your code. Please file an issue.");
|
|
595
|
+
}
|
|
596
|
+
if (cached?.staticPaths) {
|
|
597
|
+
return cached.staticPaths;
|
|
598
|
+
}
|
|
599
|
+
validateDynamicRouteModule(mod, { ssr, route });
|
|
600
|
+
if (ssr && !route.prerender) {
|
|
601
|
+
const entry = Object.assign([], { keyed: /* @__PURE__ */ new Map() });
|
|
602
|
+
routeCache.set(route, { ...cached, staticPaths: entry });
|
|
603
|
+
return entry;
|
|
604
|
+
}
|
|
605
|
+
let staticPaths = [];
|
|
606
|
+
if (!mod.getStaticPaths) {
|
|
607
|
+
throw new Error("Unexpected Error.");
|
|
608
|
+
}
|
|
609
|
+
staticPaths = await mod.getStaticPaths({
|
|
610
|
+
// Q: Why the cast?
|
|
611
|
+
// A: So users downstream can have nicer typings, we have to make some sacrifice in our internal typings, which necessitate a cast here
|
|
612
|
+
paginate: generatePaginateFunction(route)
|
|
613
|
+
});
|
|
614
|
+
validateGetStaticPathsResult(staticPaths, logger, route);
|
|
615
|
+
const keyedStaticPaths = staticPaths;
|
|
616
|
+
keyedStaticPaths.keyed = /* @__PURE__ */ new Map();
|
|
617
|
+
for (const sp of keyedStaticPaths) {
|
|
618
|
+
const paramsKey = stringifyParams(sp.params, route);
|
|
619
|
+
keyedStaticPaths.keyed.set(paramsKey, sp);
|
|
620
|
+
}
|
|
621
|
+
routeCache.set(route, { ...cached, staticPaths: keyedStaticPaths });
|
|
622
|
+
return keyedStaticPaths;
|
|
623
|
+
}
|
|
624
|
+
class RouteCache {
|
|
625
|
+
logger;
|
|
626
|
+
cache = {};
|
|
627
|
+
mode;
|
|
628
|
+
constructor(logger, mode = "production") {
|
|
629
|
+
this.logger = logger;
|
|
630
|
+
this.mode = mode;
|
|
631
|
+
}
|
|
632
|
+
/** Clear the cache. */
|
|
633
|
+
clearAll() {
|
|
634
|
+
this.cache = {};
|
|
635
|
+
}
|
|
636
|
+
set(route, entry) {
|
|
637
|
+
if (this.mode === "production" && this.cache[route.component]?.staticPaths) {
|
|
638
|
+
this.logger.warn(null, `Internal Warning: route cache overwritten. (${route.component})`);
|
|
639
|
+
}
|
|
640
|
+
this.cache[route.component] = entry;
|
|
641
|
+
}
|
|
642
|
+
get(route) {
|
|
643
|
+
return this.cache[route.component];
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
function findPathItemByKey(staticPaths, params, route, logger) {
|
|
647
|
+
const paramsKey = stringifyParams(params, route);
|
|
648
|
+
const matchedStaticPath = staticPaths.keyed.get(paramsKey);
|
|
649
|
+
if (matchedStaticPath) {
|
|
650
|
+
return matchedStaticPath;
|
|
651
|
+
}
|
|
652
|
+
logger.debug("router", `findPathItemByKey() - Unexpected cache miss looking for ${paramsKey}`);
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
async function getParamsAndProps(opts) {
|
|
656
|
+
const { logger, mod, route, routeCache, pathname, ssr } = opts;
|
|
657
|
+
if (!route || route.pathname) {
|
|
658
|
+
return [{}, {}];
|
|
659
|
+
}
|
|
660
|
+
const params = getRouteParams(route, pathname) ?? {};
|
|
661
|
+
if (routeIsRedirect(route) || routeIsFallback(route)) {
|
|
662
|
+
return [params, {}];
|
|
663
|
+
}
|
|
664
|
+
if (mod) {
|
|
665
|
+
validatePrerenderEndpointCollision(route, mod, params);
|
|
666
|
+
}
|
|
667
|
+
const staticPaths = await callGetStaticPaths({
|
|
668
|
+
mod,
|
|
669
|
+
route,
|
|
670
|
+
routeCache,
|
|
671
|
+
logger,
|
|
672
|
+
ssr
|
|
673
|
+
});
|
|
674
|
+
const matchedStaticPath = findPathItemByKey(staticPaths, params, route, logger);
|
|
675
|
+
if (!matchedStaticPath && (ssr ? route.prerender : true)) {
|
|
676
|
+
throw new AstroError({
|
|
677
|
+
...NoMatchingStaticPathFound,
|
|
678
|
+
message: NoMatchingStaticPathFound.message(pathname),
|
|
679
|
+
hint: NoMatchingStaticPathFound.hint([route.component])
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
const props = matchedStaticPath?.props ? { ...matchedStaticPath.props } : {};
|
|
683
|
+
return [params, props];
|
|
684
|
+
}
|
|
685
|
+
function getRouteParams(route, pathname) {
|
|
686
|
+
if (route.params.length) {
|
|
687
|
+
const paramsMatch = route.pattern.exec(decodeURIComponent(pathname));
|
|
688
|
+
if (paramsMatch) {
|
|
689
|
+
return getParams(route.params)(paramsMatch);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
function validatePrerenderEndpointCollision(route, mod, params) {
|
|
694
|
+
if (route.type === "endpoint" && mod.getStaticPaths) {
|
|
695
|
+
const lastSegment = route.segments[route.segments.length - 1];
|
|
696
|
+
const paramValues = Object.values(params);
|
|
697
|
+
const lastParam = paramValues[paramValues.length - 1];
|
|
698
|
+
if (lastSegment.length === 1 && lastSegment[0].dynamic && lastParam === void 0) {
|
|
699
|
+
throw new AstroError({
|
|
700
|
+
...PrerenderDynamicEndpointPathCollide,
|
|
701
|
+
message: PrerenderDynamicEndpointPathCollide.message(route.route),
|
|
702
|
+
hint: PrerenderDynamicEndpointPathCollide.hint(route.component),
|
|
703
|
+
location: {
|
|
704
|
+
file: route.component
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
const clientLocalsSymbol$2 = Symbol.for("astro.locals");
|
|
712
|
+
async function createRenderContext(options) {
|
|
713
|
+
const request = options.request;
|
|
714
|
+
const pathname = options.pathname ?? new URL(request.url).pathname;
|
|
715
|
+
const [params, props] = await getParamsAndProps({
|
|
716
|
+
mod: options.mod,
|
|
717
|
+
route: options.route,
|
|
718
|
+
routeCache: options.env.routeCache,
|
|
719
|
+
pathname,
|
|
720
|
+
logger: options.env.logger,
|
|
721
|
+
ssr: options.env.ssr
|
|
722
|
+
});
|
|
723
|
+
const context = {
|
|
724
|
+
...options,
|
|
725
|
+
pathname,
|
|
726
|
+
params,
|
|
727
|
+
props,
|
|
728
|
+
locales: options.locales,
|
|
729
|
+
routing: options.routing,
|
|
730
|
+
defaultLocale: options.defaultLocale
|
|
731
|
+
};
|
|
732
|
+
Object.defineProperty(context, "locals", {
|
|
733
|
+
enumerable: true,
|
|
734
|
+
get() {
|
|
735
|
+
return Reflect.get(request, clientLocalsSymbol$2);
|
|
736
|
+
},
|
|
737
|
+
set(val) {
|
|
738
|
+
if (typeof val !== "object") {
|
|
739
|
+
throw new AstroError(LocalsNotAnObject);
|
|
740
|
+
} else {
|
|
741
|
+
Reflect.set(request, clientLocalsSymbol$2, val);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
return context;
|
|
746
|
+
}
|
|
747
|
+
function parseLocale(header) {
|
|
748
|
+
if (header === "*") {
|
|
749
|
+
return [{ locale: header, qualityValue: void 0 }];
|
|
750
|
+
}
|
|
751
|
+
const result = [];
|
|
752
|
+
const localeValues = header.split(",").map((str) => str.trim());
|
|
753
|
+
for (const localeValue of localeValues) {
|
|
754
|
+
const split = localeValue.split(";").map((str) => str.trim());
|
|
755
|
+
const localeName = split[0];
|
|
756
|
+
const qualityValue = split[1];
|
|
757
|
+
if (!split) {
|
|
758
|
+
continue;
|
|
759
|
+
}
|
|
760
|
+
if (qualityValue && qualityValue.startsWith("q=")) {
|
|
761
|
+
const qualityValueAsFloat = Number.parseFloat(qualityValue.slice("q=".length));
|
|
762
|
+
if (Number.isNaN(qualityValueAsFloat) || qualityValueAsFloat > 1) {
|
|
763
|
+
result.push({
|
|
764
|
+
locale: localeName,
|
|
765
|
+
qualityValue: void 0
|
|
766
|
+
});
|
|
767
|
+
} else {
|
|
768
|
+
result.push({
|
|
769
|
+
locale: localeName,
|
|
770
|
+
qualityValue: qualityValueAsFloat
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
} else {
|
|
774
|
+
result.push({
|
|
775
|
+
locale: localeName,
|
|
776
|
+
qualityValue: void 0
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return result;
|
|
781
|
+
}
|
|
782
|
+
function sortAndFilterLocales(browserLocaleList, locales) {
|
|
783
|
+
const normalizedLocales = toCodes(locales).map(normalizeTheLocale);
|
|
784
|
+
return browserLocaleList.filter((browserLocale) => {
|
|
785
|
+
if (browserLocale.locale !== "*") {
|
|
786
|
+
return normalizedLocales.includes(normalizeTheLocale(browserLocale.locale));
|
|
787
|
+
}
|
|
788
|
+
return true;
|
|
789
|
+
}).sort((a, b) => {
|
|
790
|
+
if (a.qualityValue && b.qualityValue) {
|
|
791
|
+
if (a.qualityValue > b.qualityValue) {
|
|
792
|
+
return -1;
|
|
793
|
+
} else if (a.qualityValue < b.qualityValue) {
|
|
794
|
+
return 1;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
return 0;
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
function computePreferredLocale(request, locales) {
|
|
801
|
+
const acceptHeader = request.headers.get("Accept-Language");
|
|
802
|
+
let result = void 0;
|
|
803
|
+
if (acceptHeader) {
|
|
804
|
+
const browserLocaleList = sortAndFilterLocales(parseLocale(acceptHeader), locales);
|
|
805
|
+
const firstResult = browserLocaleList.at(0);
|
|
806
|
+
if (firstResult && firstResult.locale !== "*") {
|
|
807
|
+
for (const currentLocale of locales) {
|
|
808
|
+
if (typeof currentLocale === "string") {
|
|
809
|
+
if (normalizeTheLocale(currentLocale) === normalizeTheLocale(firstResult.locale)) {
|
|
810
|
+
result = currentLocale;
|
|
811
|
+
}
|
|
812
|
+
} else {
|
|
813
|
+
for (const currentCode of currentLocale.codes) {
|
|
814
|
+
if (normalizeTheLocale(currentCode) === normalizeTheLocale(firstResult.locale)) {
|
|
815
|
+
result = currentLocale.path;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
return result;
|
|
823
|
+
}
|
|
824
|
+
function computePreferredLocaleList(request, locales) {
|
|
825
|
+
const acceptHeader = request.headers.get("Accept-Language");
|
|
826
|
+
let result = [];
|
|
827
|
+
if (acceptHeader) {
|
|
828
|
+
const browserLocaleList = sortAndFilterLocales(parseLocale(acceptHeader), locales);
|
|
829
|
+
if (browserLocaleList.length === 1 && browserLocaleList.at(0).locale === "*") {
|
|
830
|
+
return locales.map((locale) => {
|
|
831
|
+
if (typeof locale === "string") {
|
|
832
|
+
return locale;
|
|
833
|
+
} else {
|
|
834
|
+
return locale.codes.at(0);
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
} else if (browserLocaleList.length > 0) {
|
|
838
|
+
for (const browserLocale of browserLocaleList) {
|
|
839
|
+
for (const loopLocale of locales) {
|
|
840
|
+
if (typeof loopLocale === "string") {
|
|
841
|
+
if (normalizeTheLocale(loopLocale) === normalizeTheLocale(browserLocale.locale)) {
|
|
842
|
+
result.push(loopLocale);
|
|
843
|
+
}
|
|
844
|
+
} else {
|
|
845
|
+
for (const code of loopLocale.codes) {
|
|
846
|
+
if (code === browserLocale.locale) {
|
|
847
|
+
result.push(loopLocale.path);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
return result;
|
|
856
|
+
}
|
|
857
|
+
function computeCurrentLocale(request, locales, routingStrategy, defaultLocale) {
|
|
858
|
+
const requestUrl = new URL(request.url);
|
|
859
|
+
for (const segment of requestUrl.pathname.split("/")) {
|
|
860
|
+
for (const locale of locales) {
|
|
861
|
+
if (typeof locale === "string") {
|
|
862
|
+
if (normalizeTheLocale(locale) === normalizeTheLocale(segment)) {
|
|
863
|
+
return locale;
|
|
864
|
+
}
|
|
865
|
+
} else {
|
|
866
|
+
if (locale.path === segment) {
|
|
867
|
+
return locale.codes.at(0);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
if (routingStrategy === "prefix-other-locales") {
|
|
873
|
+
return defaultLocale;
|
|
874
|
+
}
|
|
875
|
+
return void 0;
|
|
876
|
+
}
|
|
877
|
+
|
|
144
878
|
function createEnvironment(options) {
|
|
145
879
|
return options;
|
|
146
880
|
}
|
|
147
881
|
|
|
882
|
+
const clientAddressSymbol$2 = Symbol.for("astro.clientAddress");
|
|
883
|
+
const clientLocalsSymbol$1 = Symbol.for("astro.locals");
|
|
884
|
+
function createAPIContext({
|
|
885
|
+
request,
|
|
886
|
+
params,
|
|
887
|
+
site,
|
|
888
|
+
props,
|
|
889
|
+
adapterName,
|
|
890
|
+
locales,
|
|
891
|
+
routingStrategy,
|
|
892
|
+
defaultLocale
|
|
893
|
+
}) {
|
|
894
|
+
let preferredLocale = void 0;
|
|
895
|
+
let preferredLocaleList = void 0;
|
|
896
|
+
let currentLocale = void 0;
|
|
897
|
+
const context = {
|
|
898
|
+
cookies: new AstroCookies(request),
|
|
899
|
+
request,
|
|
900
|
+
params,
|
|
901
|
+
site: site ? new URL(site) : void 0,
|
|
902
|
+
generator: `Astro v${ASTRO_VERSION}`,
|
|
903
|
+
props,
|
|
904
|
+
redirect(path, status) {
|
|
905
|
+
return new Response(null, {
|
|
906
|
+
status: status || 302,
|
|
907
|
+
headers: {
|
|
908
|
+
Location: path
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
},
|
|
912
|
+
get preferredLocale() {
|
|
913
|
+
if (preferredLocale) {
|
|
914
|
+
return preferredLocale;
|
|
915
|
+
}
|
|
916
|
+
if (locales) {
|
|
917
|
+
preferredLocale = computePreferredLocale(request, locales);
|
|
918
|
+
return preferredLocale;
|
|
919
|
+
}
|
|
920
|
+
return void 0;
|
|
921
|
+
},
|
|
922
|
+
get preferredLocaleList() {
|
|
923
|
+
if (preferredLocaleList) {
|
|
924
|
+
return preferredLocaleList;
|
|
925
|
+
}
|
|
926
|
+
if (locales) {
|
|
927
|
+
preferredLocaleList = computePreferredLocaleList(request, locales);
|
|
928
|
+
return preferredLocaleList;
|
|
929
|
+
}
|
|
930
|
+
return void 0;
|
|
931
|
+
},
|
|
932
|
+
get currentLocale() {
|
|
933
|
+
if (currentLocale) {
|
|
934
|
+
return currentLocale;
|
|
935
|
+
}
|
|
936
|
+
if (locales) {
|
|
937
|
+
currentLocale = computeCurrentLocale(request, locales, routingStrategy, defaultLocale);
|
|
938
|
+
}
|
|
939
|
+
return currentLocale;
|
|
940
|
+
},
|
|
941
|
+
url: new URL(request.url),
|
|
942
|
+
get clientAddress() {
|
|
943
|
+
if (clientAddressSymbol$2 in request) {
|
|
944
|
+
return Reflect.get(request, clientAddressSymbol$2);
|
|
945
|
+
}
|
|
946
|
+
if (adapterName) {
|
|
947
|
+
throw new AstroError({
|
|
948
|
+
...ClientAddressNotAvailable,
|
|
949
|
+
message: ClientAddressNotAvailable.message(adapterName)
|
|
950
|
+
});
|
|
951
|
+
} else {
|
|
952
|
+
throw new AstroError(StaticClientAddressNotAvailable);
|
|
953
|
+
}
|
|
954
|
+
},
|
|
955
|
+
get locals() {
|
|
956
|
+
let locals = Reflect.get(request, clientLocalsSymbol$1);
|
|
957
|
+
if (locals === void 0) {
|
|
958
|
+
locals = {};
|
|
959
|
+
Reflect.set(request, clientLocalsSymbol$1, locals);
|
|
960
|
+
}
|
|
961
|
+
if (typeof locals !== "object") {
|
|
962
|
+
throw new AstroError(LocalsNotAnObject);
|
|
963
|
+
}
|
|
964
|
+
return locals;
|
|
965
|
+
},
|
|
966
|
+
// We define a custom property, so we can check the value passed to locals
|
|
967
|
+
set locals(val) {
|
|
968
|
+
if (typeof val !== "object") {
|
|
969
|
+
throw new AstroError(LocalsNotAnObject);
|
|
970
|
+
} else {
|
|
971
|
+
Reflect.set(request, clientLocalsSymbol$1, val);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
return context;
|
|
976
|
+
}
|
|
977
|
+
async function callEndpoint(mod, env, ctx, onRequest) {
|
|
978
|
+
const context = createAPIContext({
|
|
979
|
+
request: ctx.request,
|
|
980
|
+
params: ctx.params,
|
|
981
|
+
props: ctx.props,
|
|
982
|
+
site: env.site,
|
|
983
|
+
adapterName: env.adapterName,
|
|
984
|
+
routingStrategy: ctx.routing,
|
|
985
|
+
defaultLocale: ctx.defaultLocale,
|
|
986
|
+
locales: ctx.locales
|
|
987
|
+
});
|
|
988
|
+
let response;
|
|
989
|
+
if (onRequest) {
|
|
990
|
+
response = await callMiddleware(onRequest, context, async () => {
|
|
991
|
+
return await renderEndpoint(mod, context, env.ssr, env.logger);
|
|
992
|
+
});
|
|
993
|
+
} else {
|
|
994
|
+
response = await renderEndpoint(mod, context, env.ssr, env.logger);
|
|
995
|
+
}
|
|
996
|
+
attachCookiesToResponse(response, context.cookies);
|
|
997
|
+
return response;
|
|
998
|
+
}
|
|
999
|
+
|
|
148
1000
|
function sequence(...handlers) {
|
|
149
1001
|
const filtered = handlers.filter((h) => !!h);
|
|
150
1002
|
const length = filtered.length;
|
|
@@ -276,7 +1128,7 @@ class Slots {
|
|
|
276
1128
|
const result = this.#result;
|
|
277
1129
|
if (!Array.isArray(args)) {
|
|
278
1130
|
this.#logger.warn(
|
|
279
|
-
|
|
1131
|
+
null,
|
|
280
1132
|
`Expected second parameter to be an array, received a ${typeof args}. If you're trying to pass an array as a single argument and getting unexpected results, make sure you're passing your array as a item of an array. Ex: Astro.slots.render('default', [["Hello", "World"]])`
|
|
281
1133
|
);
|
|
282
1134
|
} else if (args.length > 0) {
|
|
@@ -471,19 +1323,13 @@ async function renderPage({ mod, renderContext, env, cookies }) {
|
|
|
471
1323
|
locals: renderContext.locals ?? {},
|
|
472
1324
|
locales: renderContext.locales,
|
|
473
1325
|
defaultLocale: renderContext.defaultLocale,
|
|
474
|
-
routingStrategy: renderContext.
|
|
1326
|
+
routingStrategy: renderContext.routing
|
|
475
1327
|
});
|
|
476
|
-
if (mod.frontmatter && typeof mod.frontmatter === "object" && "draft" in mod.frontmatter) {
|
|
477
|
-
env.logger.warn(
|
|
478
|
-
"astro",
|
|
479
|
-
`The drafts feature is deprecated and used in ${renderContext.route.component}. You should migrate to content collections instead. See https://docs.astro.build/en/guides/content-collections/#filtering-collection-queries for more information.`
|
|
480
|
-
);
|
|
481
|
-
}
|
|
482
1328
|
const response = await renderPage$1(
|
|
483
1329
|
result,
|
|
484
1330
|
Component,
|
|
485
1331
|
renderContext.props,
|
|
486
|
-
|
|
1332
|
+
{},
|
|
487
1333
|
env.streaming,
|
|
488
1334
|
renderContext.route
|
|
489
1335
|
);
|
|
@@ -581,7 +1427,7 @@ class Pipeline {
|
|
|
581
1427
|
site: env.site,
|
|
582
1428
|
adapterName: env.adapterName,
|
|
583
1429
|
locales: renderContext.locales,
|
|
584
|
-
routingStrategy: renderContext.
|
|
1430
|
+
routingStrategy: renderContext.routing,
|
|
585
1431
|
defaultLocale: renderContext.defaultLocale
|
|
586
1432
|
});
|
|
587
1433
|
switch (renderContext.route.type) {
|
|
@@ -589,19 +1435,14 @@ class Pipeline {
|
|
|
589
1435
|
case "fallback":
|
|
590
1436
|
case "redirect": {
|
|
591
1437
|
if (onRequest) {
|
|
592
|
-
return await callMiddleware(
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
env,
|
|
601
|
-
cookies: apiContext.cookies
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
);
|
|
1438
|
+
return await callMiddleware(onRequest, apiContext, () => {
|
|
1439
|
+
return renderPage({
|
|
1440
|
+
mod,
|
|
1441
|
+
renderContext,
|
|
1442
|
+
env,
|
|
1443
|
+
cookies: apiContext.cookies
|
|
1444
|
+
});
|
|
1445
|
+
});
|
|
605
1446
|
} else {
|
|
606
1447
|
return await renderPage({
|
|
607
1448
|
mod,
|
|
@@ -665,6 +1506,7 @@ class App {
|
|
|
665
1506
|
#baseWithoutTrailingSlash;
|
|
666
1507
|
#pipeline;
|
|
667
1508
|
#adapterLogger;
|
|
1509
|
+
#renderOptionsDeprecationWarningShown = false;
|
|
668
1510
|
constructor(manifest, streaming = true) {
|
|
669
1511
|
this.#manifest = manifest;
|
|
670
1512
|
this.#manifestData = {
|
|
@@ -730,7 +1572,7 @@ class App {
|
|
|
730
1572
|
const pathname = prependForwardSlash(this.removeBase(url.pathname));
|
|
731
1573
|
return pathname;
|
|
732
1574
|
}
|
|
733
|
-
match(request
|
|
1575
|
+
match(request) {
|
|
734
1576
|
const url = new URL(request.url);
|
|
735
1577
|
if (this.#manifest.assets.has(url.pathname))
|
|
736
1578
|
return void 0;
|
|
@@ -740,7 +1582,23 @@ class App {
|
|
|
740
1582
|
return void 0;
|
|
741
1583
|
return routeData;
|
|
742
1584
|
}
|
|
743
|
-
async render(request,
|
|
1585
|
+
async render(request, routeDataOrOptions, maybeLocals) {
|
|
1586
|
+
let routeData;
|
|
1587
|
+
let locals;
|
|
1588
|
+
if (routeDataOrOptions && ("routeData" in routeDataOrOptions || "locals" in routeDataOrOptions)) {
|
|
1589
|
+
if ("routeData" in routeDataOrOptions) {
|
|
1590
|
+
routeData = routeDataOrOptions.routeData;
|
|
1591
|
+
}
|
|
1592
|
+
if ("locals" in routeDataOrOptions) {
|
|
1593
|
+
locals = routeDataOrOptions.locals;
|
|
1594
|
+
}
|
|
1595
|
+
} else {
|
|
1596
|
+
routeData = routeDataOrOptions;
|
|
1597
|
+
locals = maybeLocals;
|
|
1598
|
+
if (routeDataOrOptions || locals) {
|
|
1599
|
+
this.#logRenderOptionsDeprecationWarning();
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
744
1602
|
if (request.url !== collapseDuplicateSlashes(request.url)) {
|
|
745
1603
|
request = new Request(collapseDuplicateSlashes(request.url), request);
|
|
746
1604
|
}
|
|
@@ -772,9 +1630,7 @@ class App {
|
|
|
772
1630
|
);
|
|
773
1631
|
if (i18nMiddleware) {
|
|
774
1632
|
if (mod.onRequest) {
|
|
775
|
-
this.#pipeline.setMiddlewareFunction(
|
|
776
|
-
sequence(i18nMiddleware, mod.onRequest)
|
|
777
|
-
);
|
|
1633
|
+
this.#pipeline.setMiddlewareFunction(sequence(i18nMiddleware, mod.onRequest));
|
|
778
1634
|
} else {
|
|
779
1635
|
this.#pipeline.setMiddlewareFunction(i18nMiddleware);
|
|
780
1636
|
}
|
|
@@ -789,7 +1645,7 @@ class App {
|
|
|
789
1645
|
if (err instanceof EndpointNotFoundError) {
|
|
790
1646
|
return this.#renderError(request, { status: 404, response: err.originalResponse });
|
|
791
1647
|
} else {
|
|
792
|
-
this.#logger.error(
|
|
1648
|
+
this.#logger.error(null, err.stack || err.message || String(err));
|
|
793
1649
|
return this.#renderError(request, { status: 500 });
|
|
794
1650
|
}
|
|
795
1651
|
}
|
|
@@ -805,6 +1661,15 @@ class App {
|
|
|
805
1661
|
}
|
|
806
1662
|
return response;
|
|
807
1663
|
}
|
|
1664
|
+
#logRenderOptionsDeprecationWarning() {
|
|
1665
|
+
if (this.#renderOptionsDeprecationWarningShown)
|
|
1666
|
+
return;
|
|
1667
|
+
this.#logger.warn(
|
|
1668
|
+
"deprecated",
|
|
1669
|
+
`The adapter ${this.#manifest.adapterName} is using a deprecated signature of the 'app.render()' method. From Astro 4.0, locals and routeData are provided as properties on an optional object to this method. Using the old signature will cause an error in Astro 5.0. See https://github.com/withastro/astro/pull/9199 for more information.`
|
|
1670
|
+
);
|
|
1671
|
+
this.#renderOptionsDeprecationWarningShown = true;
|
|
1672
|
+
}
|
|
808
1673
|
setCookieHeaders(response) {
|
|
809
1674
|
return getSetCookiesFromResponse(response);
|
|
810
1675
|
}
|
|
@@ -824,7 +1689,7 @@ class App {
|
|
|
824
1689
|
env: this.#pipeline.env,
|
|
825
1690
|
mod: handler,
|
|
826
1691
|
locales: this.#manifest.i18n?.locales,
|
|
827
|
-
|
|
1692
|
+
routing: this.#manifest.i18n?.routing,
|
|
828
1693
|
defaultLocale: this.#manifest.i18n?.defaultLocale
|
|
829
1694
|
});
|
|
830
1695
|
} else {
|
|
@@ -858,7 +1723,7 @@ class App {
|
|
|
858
1723
|
mod,
|
|
859
1724
|
env: this.#pipeline.env,
|
|
860
1725
|
locales: this.#manifest.i18n?.locales,
|
|
861
|
-
|
|
1726
|
+
routing: this.#manifest.i18n?.routing,
|
|
862
1727
|
defaultLocale: this.#manifest.i18n?.defaultLocale
|
|
863
1728
|
});
|
|
864
1729
|
}
|
|
@@ -1051,19 +1916,19 @@ function asyncIterableToBodyProps(iterable) {
|
|
|
1051
1916
|
};
|
|
1052
1917
|
}
|
|
1053
1918
|
class NodeApp extends App {
|
|
1054
|
-
match(req
|
|
1919
|
+
match(req) {
|
|
1055
1920
|
if (!(req instanceof Request)) {
|
|
1056
1921
|
req = createRequestFromNodeRequest(req, {
|
|
1057
1922
|
emptyBody: true
|
|
1058
1923
|
});
|
|
1059
1924
|
}
|
|
1060
|
-
return super.match(req
|
|
1925
|
+
return super.match(req);
|
|
1061
1926
|
}
|
|
1062
|
-
render(req,
|
|
1927
|
+
render(req, routeDataOrOptions, maybeLocals) {
|
|
1063
1928
|
if (!(req instanceof Request)) {
|
|
1064
1929
|
req = createRequestFromNodeRequest(req);
|
|
1065
1930
|
}
|
|
1066
|
-
return super.render(req,
|
|
1931
|
+
return super.render(req, routeDataOrOptions, maybeLocals);
|
|
1067
1932
|
}
|
|
1068
1933
|
}
|
|
1069
1934
|
|
|
@@ -1108,10 +1973,10 @@ function nodeMiddleware_default(app, mode) {
|
|
|
1108
1973
|
}
|
|
1109
1974
|
}
|
|
1110
1975
|
try {
|
|
1111
|
-
const
|
|
1112
|
-
if (
|
|
1976
|
+
const routeData = app.match(req);
|
|
1977
|
+
if (routeData) {
|
|
1113
1978
|
try {
|
|
1114
|
-
const response = await app.render(req,
|
|
1979
|
+
const response = await app.render(req, { routeData, locals });
|
|
1115
1980
|
await writeWebResponse(app, res, response);
|
|
1116
1981
|
} catch (err) {
|
|
1117
1982
|
if (next) {
|
|
@@ -1203,7 +2068,11 @@ function parsePathname(pathname, host, port) {
|
|
|
1203
2068
|
return void 0;
|
|
1204
2069
|
}
|
|
1205
2070
|
}
|
|
1206
|
-
function createServer({ client, port, host, removeBase }, handler) {
|
|
2071
|
+
function createServer({ client, port, host, removeBase, assets }, handler) {
|
|
2072
|
+
const assetsPrefix = `/${assets}/`;
|
|
2073
|
+
function isImmutableAsset(pathname) {
|
|
2074
|
+
return pathname.startsWith(assetsPrefix);
|
|
2075
|
+
}
|
|
1207
2076
|
const listener = (req, res) => {
|
|
1208
2077
|
if (req.url) {
|
|
1209
2078
|
let pathname = removeBase(req.url);
|
|
@@ -1228,6 +2097,11 @@ function createServer({ client, port, host, removeBase }, handler) {
|
|
|
1228
2097
|
}
|
|
1229
2098
|
handler(req, res);
|
|
1230
2099
|
});
|
|
2100
|
+
stream.on("headers", (_res) => {
|
|
2101
|
+
if (isImmutableAsset(encodedURI)) {
|
|
2102
|
+
_res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
|
|
2103
|
+
}
|
|
2104
|
+
});
|
|
1231
2105
|
stream.on("directory", () => {
|
|
1232
2106
|
let location;
|
|
1233
2107
|
if (req.url.includes("?")) {
|
|
@@ -1316,7 +2190,8 @@ function startServer$1(app, options) {
|
|
|
1316
2190
|
client,
|
|
1317
2191
|
port,
|
|
1318
2192
|
host,
|
|
1319
|
-
removeBase: app.removeBase.bind(app)
|
|
2193
|
+
removeBase: app.removeBase.bind(app),
|
|
2194
|
+
assets: options.assets
|
|
1320
2195
|
},
|
|
1321
2196
|
handler
|
|
1322
2197
|
);
|
|
@@ -1342,6 +2217,7 @@ apply();
|
|
|
1342
2217
|
function createExports(manifest, options) {
|
|
1343
2218
|
const app = new NodeApp(manifest);
|
|
1344
2219
|
return {
|
|
2220
|
+
options,
|
|
1345
2221
|
handler: nodeMiddleware_default(app, options.mode),
|
|
1346
2222
|
startServer: () => startServer$1(app, options)
|
|
1347
2223
|
};
|
|
@@ -1360,25 +2236,26 @@ const adapter = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
|
1360
2236
|
start
|
|
1361
2237
|
}, Symbol.toStringTag, { value: 'Module' }));
|
|
1362
2238
|
|
|
1363
|
-
const _page0 = () => import('./chunks/
|
|
1364
|
-
const _page1 = () => import('./chunks/
|
|
1365
|
-
const _page2 = () => import('./chunks/~
|
|
1366
|
-
const _page3 = () => import('./chunks/
|
|
1367
|
-
const _page4 = () => import('./chunks/
|
|
1368
|
-
const _page5 = () => import('./chunks/_..
|
|
2239
|
+
const _page0 = () => import('./chunks/node_2VvC7trl.mjs');
|
|
2240
|
+
const _page1 = () => import('./chunks/index_nIwq11oA.mjs');
|
|
2241
|
+
const _page2 = () => import('./chunks/~fallback_7q1dqY4e.mjs');
|
|
2242
|
+
const _page3 = () => import('./chunks/index_uAR5ZV4d.mjs');
|
|
2243
|
+
const _page4 = () => import('./chunks/account_3ySmGzMc.mjs');
|
|
2244
|
+
const _page5 = () => import('./chunks/_.._S7DDBn_b.mjs');const pageMap = new Map([["../../node_modules/.pnpm/astro@4.0.4_@types+node@18.19.3_typescript@5.2.2/node_modules/astro/dist/assets/endpoint/node.js", _page0],["src/pages/index.astro", _page1],["src/pages/~fallback.astro", _page2],["src/pages/app/index.astro", _page3],["src/pages/app/account.astro", _page4],["src/pages/[...slug].astro", _page5]]);
|
|
1369
2245
|
const _manifest = Object.assign(manifest, {
|
|
1370
2246
|
pageMap,
|
|
1371
2247
|
renderers,
|
|
1372
2248
|
});
|
|
1373
|
-
const _args = {"mode":"middleware","client":"file:///home/leo/code/ecomplus/cloud-commerce/packages/storefront/dist/client/","server":"file:///home/leo/code/ecomplus/cloud-commerce/packages/storefront/dist/server/","host":false,"port":4321};
|
|
2249
|
+
const _args = {"mode":"middleware","client":"file:///home/leo/code/ecomplus/cloud-commerce/packages/storefront/dist/client/","server":"file:///home/leo/code/ecomplus/cloud-commerce/packages/storefront/dist/server/","host":false,"port":4321,"assets":"_astro"};
|
|
1374
2250
|
|
|
1375
2251
|
const _exports = createExports(_manifest, _args);
|
|
1376
2252
|
const handler = _exports['handler'];
|
|
1377
2253
|
const startServer = _exports['startServer'];
|
|
2254
|
+
const options = _exports['options'];
|
|
1378
2255
|
|
|
1379
2256
|
const _start = 'start';
|
|
1380
2257
|
if(_start in adapter) {
|
|
1381
2258
|
adapter[_start](_manifest, _args);
|
|
1382
2259
|
}
|
|
1383
2260
|
|
|
1384
|
-
export { handler, pageMap, startServer };
|
|
2261
|
+
export { handler, options, pageMap, startServer };
|