cloudcommerce 2.0.7 → 2.0.9

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 (168) hide show
  1. package/.husky/pre-commit +4 -0
  2. package/.vscode/settings.json +8 -2
  3. package/CHANGELOG.md +20 -0
  4. package/action.yml +1 -1
  5. package/ecomplus-stores/barra-doce/.husky/pre-commit +4 -0
  6. package/ecomplus-stores/barra-doce/.vscode/settings.json +3 -2
  7. package/ecomplus-stores/barra-doce/functions/many/package.json +3 -3
  8. package/ecomplus-stores/barra-doce/functions/ssr/.staged.eslintrc.cjs +6 -0
  9. package/ecomplus-stores/barra-doce/functions/ssr/package.json +9 -8
  10. package/ecomplus-stores/barra-doce/functions/ssr/src/components/AccountMenu.vue +4 -1
  11. package/ecomplus-stores/barra-doce/functions/ssr/src/components/AccountPage.vue +6 -3
  12. package/ecomplus-stores/barra-doce/functions/ssr/src/components/Banner.vue +2 -1
  13. package/ecomplus-stores/barra-doce/functions/ssr/src/components/BlogPosts.vue +8 -2
  14. package/ecomplus-stores/barra-doce/functions/ssr/src/components/Breadcrumbs.vue +4 -1
  15. package/ecomplus-stores/barra-doce/functions/ssr/src/components/CartItem.vue +4 -3
  16. package/ecomplus-stores/barra-doce/functions/ssr/src/components/CartSidebar.vue +1 -1
  17. package/ecomplus-stores/barra-doce/functions/ssr/src/components/CheckoutPage.vue +2 -2
  18. package/ecomplus-stores/barra-doce/functions/ssr/src/components/ContentEntry.vue +1 -1
  19. package/ecomplus-stores/barra-doce/functions/ssr/src/components/FooterStamps.vue +8 -6
  20. package/ecomplus-stores/barra-doce/functions/ssr/src/components/HeroSlider.vue +7 -3
  21. package/ecomplus-stores/barra-doce/functions/ssr/src/components/ImagesGallery.vue +13 -11
  22. package/ecomplus-stores/barra-doce/functions/ssr/src/components/LoginForm.vue +1 -1
  23. package/ecomplus-stores/barra-doce/functions/ssr/src/components/PitchBar.vue +5 -2
  24. package/ecomplus-stores/barra-doce/functions/ssr/src/components/Prices.vue +1 -1
  25. package/ecomplus-stores/barra-doce/functions/ssr/src/components/ProductCard.vue +13 -13
  26. package/ecomplus-stores/barra-doce/functions/ssr/src/components/ProductDetails.vue +1 -1
  27. package/ecomplus-stores/barra-doce/functions/ssr/src/components/ProductShelf.vue +9 -6
  28. package/ecomplus-stores/barra-doce/functions/ssr/src/components/SearchModal.vue +1 -1
  29. package/ecomplus-stores/barra-doce/functions/ssr/src/components/SearchShowcase.vue +8 -9
  30. package/ecomplus-stores/barra-doce/functions/ssr/src/components/ShopFooter.vue +15 -6
  31. package/ecomplus-stores/barra-doce/functions/ssr/src/components/ShopHeader.vue +10 -10
  32. package/ecomplus-stores/barra-doce/functions/ssr/src/components/ShopHeaderMenu.vue +2 -1
  33. package/ecomplus-stores/barra-doce/functions/ssr/src/components/ShopHeaderSubmenu.vue +7 -4
  34. package/ecomplus-stores/barra-doce/functions/ssr/src/components/ShopSidenav.vue +5 -2
  35. package/ecomplus-stores/barra-doce/functions/ssr/src/components/ShopSidenavCategory.vue +3 -2
  36. package/ecomplus-stores/barra-doce/functions/ssr/src/components/SkuSelector.vue +8 -5
  37. package/ecomplus-stores/barra-doce/functions/ssr/src/layouts/PageFooter.astro +1 -2
  38. package/ecomplus-stores/barra-doce/functions/ssr/src/layouts/PageHeader.astro +2 -1
  39. package/ecomplus-stores/barra-doce/functions/ssr/src/main/Fallback.astro +3 -3
  40. package/ecomplus-stores/barra-doce/functions/ssr/src/main/Main.astro +2 -2
  41. package/ecomplus-stores/barra-doce/functions/ssr/src/pages/[...slug].astro +4 -4
  42. package/ecomplus-stores/barra-doce/functions/ssr/src/scripts/InlineScripts.astro +8 -8
  43. package/ecomplus-stores/barra-doce/functions/with-apps/package.json +3 -3
  44. package/ecomplus-stores/barra-doce/package.json +10 -3
  45. package/ecomplus-stores/barra-doce/tailwind.config.cjs +5 -0
  46. package/ecomplus-stores/tia-sonia/.vscode/launch.json +11 -0
  47. package/ecomplus-stores/tia-sonia/.vscode/settings.json +7 -1
  48. package/package.json +9 -4
  49. package/packages/api/package.json +1 -1
  50. package/packages/apps/affiliate-program/package.json +1 -1
  51. package/packages/apps/correios/package.json +2 -2
  52. package/packages/apps/custom-payment/package.json +1 -1
  53. package/packages/apps/custom-shipping/package.json +1 -1
  54. package/packages/apps/datafrete/package.json +1 -1
  55. package/packages/apps/discounts/package.json +1 -1
  56. package/packages/apps/emails/package.json +1 -1
  57. package/packages/apps/fb-conversions/package.json +1 -1
  58. package/packages/apps/flash-courier/package.json +1 -1
  59. package/packages/apps/frenet/package.json +1 -1
  60. package/packages/apps/galaxpay/package.json +1 -1
  61. package/packages/apps/google-analytics/package.json +1 -1
  62. package/packages/apps/jadlog/package.json +1 -1
  63. package/packages/apps/loyalty-points/package.json +1 -1
  64. package/packages/apps/mandae/package.json +1 -1
  65. package/packages/apps/melhor-envio/package.json +1 -1
  66. package/packages/apps/mercadopago/package.json +1 -1
  67. package/packages/apps/pagarme/package.json +1 -1
  68. package/packages/apps/pagarme-v5/package.json +1 -1
  69. package/packages/apps/paghiper/package.json +1 -1
  70. package/packages/apps/pix/package.json +1 -1
  71. package/packages/apps/tiny-erp/package.json +1 -1
  72. package/packages/apps/webhooks/package.json +1 -1
  73. package/packages/cli/package.json +1 -1
  74. package/packages/config/package.json +1 -1
  75. package/packages/emails/package.json +1 -1
  76. package/packages/eslint/base.eslintrc.cjs +3 -4
  77. package/packages/eslint/package.json +6 -5
  78. package/packages/eslint/storefront.eslintrc.cjs +19 -2
  79. package/packages/eslint/storefront.staged.eslintrc.cjs +9 -0
  80. package/packages/events/package.json +1 -1
  81. package/packages/feeds/package.json +1 -1
  82. package/packages/firebase/package.json +2 -2
  83. package/packages/i18n/package.json +1 -1
  84. package/packages/modules/package.json +2 -2
  85. package/packages/passport/package.json +1 -1
  86. package/packages/ssr/package.json +5 -5
  87. package/packages/storefront/dist/client/_astro/{AccountPage.oxrx8xO0.js → AccountPage.9BlGHXT3.js} +1 -1
  88. package/packages/storefront/dist/client/_astro/CartSidebar.55UgTcV0.js +1 -0
  89. package/packages/storefront/dist/client/_astro/{HeroSlider.OYdereCn.js → HeroSlider.XZb2xsyV.js} +1 -1
  90. package/packages/storefront/dist/client/_astro/{PitchBar.RVEArMQA.js → PitchBar.Nr7T3S3T.js} +1 -1
  91. package/packages/storefront/dist/client/_astro/{Prices.Bsod-tLh.js → Prices.Ye-m2HTo.js} +1 -1
  92. package/packages/storefront/dist/client/_astro/ProductDetails.ENLKdSz_.js +7 -0
  93. package/packages/storefront/dist/client/_astro/ProductShelf.CNf5JDrU.js +1 -0
  94. package/packages/storefront/dist/client/_astro/ProductShelf.lCBJky3e.js +1 -0
  95. package/packages/storefront/dist/client/_astro/{QuantitySelector.SEAsIOhe.js → QuantitySelector.tumfWDjC.js} +1 -1
  96. package/packages/storefront/dist/client/_astro/{SearchModal.JVuqMQFe.js → SearchModal.4osqtafp.js} +1 -1
  97. package/packages/storefront/dist/client/_astro/{SearchShowcase.zwEq0xsL.js → SearchShowcase.hg6TWrz3.js} +1 -1
  98. package/packages/storefront/dist/client/_astro/ShopHeader.xLMeJpqV.js +7 -0
  99. package/packages/storefront/dist/client/_astro/_plugin-vue_export-helper.SO-0jCqa.js +5 -0
  100. package/packages/storefront/dist/client/_astro/_slug_.r344YGqG.css +1 -0
  101. package/packages/storefront/dist/client/_astro/client.ZhEmw4hZ.js +1 -0
  102. package/packages/storefront/dist/client/_astro/{customer-session.yn5lG3w3.js → customer-session.hXdZh5Ii.js} +1 -1
  103. package/packages/storefront/dist/client/_astro/{format-money.ykh8O7d2.js → format-money.iK5LGydz.js} +1 -1
  104. package/packages/storefront/dist/client/_astro/{grid-title.z5ui_5pL.js → grid-title.vGKBy72g.js} +1 -1
  105. package/packages/storefront/dist/client/_astro/{hoisted.hpPOAcMM.js → hoisted.HGTzAuTI.js} +1 -1
  106. package/packages/storefront/dist/client/_astro/{hoisted.daSrX1-i.js → hoisted.J15ErMtK.js} +1 -1
  107. package/packages/storefront/dist/client/_astro/hoisted.KYhwGfsv.js +1 -0
  108. package/packages/storefront/dist/client/_astro/{i18n.MycOopxQ.js → i18n.Lxnz1oF-.js} +1 -1
  109. package/packages/storefront/dist/client/_astro/{img.c2KI4eO6.js → img.WnsidxCx.js} +1 -1
  110. package/packages/storefront/dist/client/_astro/{index.NRzvVgQf.js → index.R7A-Pg5V.js} +1 -1
  111. package/packages/storefront/dist/client/_astro/{index.8acAQSHW.js → index.q6KIyKlJ.js} +1 -1
  112. package/packages/storefront/dist/client/_astro/{modules-info.dHD0h8Nc.js → modules-info.tVRhvxNm.js} +1 -1
  113. package/packages/storefront/dist/client/_astro/name.urFqJ5yn.js +1 -0
  114. package/packages/storefront/dist/client/_astro/runtime-core.esm-bundler.XTSAdOlw.js +13 -0
  115. package/packages/storefront/dist/client/_astro/sf-utils.Z4H-dRBJ.js +1 -0
  116. package/packages/storefront/dist/client/_astro/{shopping-cart.MgpVRgys.js → shopping-cart.ZdSCrjS6.js} +1 -1
  117. package/packages/storefront/dist/client/_astro/{use-analytics.D9xd-k7D.js → use-analytics.tCrQbW8O.js} +1 -1
  118. package/packages/storefront/dist/client/_astro/{use-product-card.gKh9czSW.js → use-product-card.-9TsgDDW.js} +1 -1
  119. package/packages/storefront/dist/client/_astro/use-text-value.XE_A2nDM.js +4 -0
  120. package/packages/storefront/dist/server/chunks/{CartSidebar_8VAKl-jR.mjs → CartSidebar_7UWmGIF6.mjs} +5 -5
  121. package/packages/storefront/dist/server/chunks/{SearchModal_7debttOi.mjs → SearchModal_MNdcYMws.mjs} +4 -4
  122. package/packages/storefront/dist/server/chunks/{_.._D6rq0cLa.mjs → _.._h5R83hoK.mjs} +1 -1
  123. package/packages/storefront/dist/server/chunks/{_page__WXDIwV7g.mjs → _page__lWVlZyRe.mjs} +1 -1
  124. package/packages/storefront/dist/server/chunks/{account_DOT2RzND.mjs → account_jmelxnlw.mjs} +1 -1
  125. package/packages/storefront/dist/server/chunks/astro/{assets-service_gJYJeEDH.mjs → assets-service_xNulQtBO.mjs} +1 -1
  126. package/packages/storefront/dist/server/chunks/{astro_H-6uiAAG.mjs → astro_tggR3S_9.mjs} +2 -2
  127. package/packages/storefront/dist/server/chunks/{index_eXlHIU83.mjs → index_e3ytAL8v.mjs} +1 -1
  128. package/packages/storefront/dist/server/chunks/{node_-eQO2yOn.mjs → node_kUJIRL0c.mjs} +1 -1
  129. package/packages/storefront/dist/server/chunks/pages/{__fI3NeWvy.mjs → __wihn0dYD.mjs} +864 -856
  130. package/packages/storefront/dist/server/chunks/pages/{_page__Piz8geXW.mjs → _page__Sb1eYhpz.mjs} +2 -2
  131. package/packages/storefront/dist/server/chunks/pages/{account_6pD7OYw-.mjs → account_-mULVQUB.mjs} +2 -2
  132. package/packages/storefront/dist/server/chunks/pages/{index_2F5yi6YO.mjs → index_mQXYNYRg.mjs} +4 -4
  133. package/packages/storefront/dist/server/chunks/pages/{node_-Buhxl8v.mjs → node_-qe5LuQh.mjs} +3 -3
  134. package/packages/storefront/dist/server/chunks/pages/{~fallback_okEL1qQ3.mjs → ~fallback_ad_xyGHU.mjs} +4 -4
  135. package/packages/storefront/dist/server/chunks/~fallback_EZqiEAFE.mjs +6 -0
  136. package/packages/storefront/dist/server/entry.mjs +376 -307
  137. package/packages/storefront/dist/server/manifest_RrmXPEuL.mjs +196 -0
  138. package/packages/storefront/dist/server/renderers.mjs +1 -1
  139. package/packages/storefront/package.json +7 -6
  140. package/packages/storefront/src/helpers/server-data.ts +2 -1
  141. package/packages/storefront/src/lib/components/BannerPictures.astro +7 -6
  142. package/packages/storefront/src/lib/components/CarouselControl.vue +2 -2
  143. package/packages/storefront/src/lib/components/ContentClearfix.vue +1 -1
  144. package/packages/storefront/src/lib/components/Drawer.vue +2 -2
  145. package/packages/storefront/src/lib/components/Picture.astro +2 -2
  146. package/packages/storefront/src/lib/components/QuantitySelectorControl.vue +2 -2
  147. package/packages/storefront/src/lib/components/ViewTransitions.astro +1 -0
  148. package/packages/storefront/src/lib/layouts/BaseBody.astro +3 -3
  149. package/packages/storefront/src/lib/layouts/BaseHead.astro +29 -29
  150. package/packages/storefront/src/lib/pages/_vue.ts +3 -2
  151. package/packages/test-base/package.json +1 -1
  152. package/packages/types/package.json +1 -1
  153. package/tailwind.config.cjs +5 -0
  154. package/packages/storefront/dist/client/_astro/CartSidebar.ShqcM66P.js +0 -1
  155. package/packages/storefront/dist/client/_astro/ProductDetails.TQM36pzk.js +0 -7
  156. package/packages/storefront/dist/client/_astro/ProductShelf.HX1P9sTW.js +0 -1
  157. package/packages/storefront/dist/client/_astro/ProductShelf._0iHMZBO.js +0 -1
  158. package/packages/storefront/dist/client/_astro/ShopHeader.BoPmUmjI.js +0 -7
  159. package/packages/storefront/dist/client/_astro/_plugin-vue_export-helper.40kDRyEO.js +0 -1
  160. package/packages/storefront/dist/client/_astro/_slug_.PTG68eA8.css +0 -1
  161. package/packages/storefront/dist/client/_astro/client.nPN_zw-c.js +0 -1
  162. package/packages/storefront/dist/client/_astro/hoisted.FcmEawNA.js +0 -1
  163. package/packages/storefront/dist/client/_astro/name.itYHl42A.js +0 -1
  164. package/packages/storefront/dist/client/_astro/runtime-core.esm-bundler.Pr2hdd7G.js +0 -1
  165. package/packages/storefront/dist/client/_astro/sf-utils.yjuG8NjM.js +0 -1
  166. package/packages/storefront/dist/client/_astro/use-text-value.ZIz7zsXT.js +0 -4
  167. package/packages/storefront/dist/server/chunks/~fallback_M-xiy2GE.mjs +0 -6
  168. package/packages/storefront/dist/server/manifest_oV2meNKS.mjs +0 -196
@@ -1,20 +1,20 @@
1
1
  import fs from 'node:fs';
2
- import http from 'node:http';
3
- import { TLSSocket } from 'node:tls';
4
2
  import { appendForwardSlash as appendForwardSlash$1, joinPaths, trimSlashes, slash, prependForwardSlash, removeTrailingForwardSlash, collapseDuplicateSlashes } from '@astrojs/internal-helpers/path';
5
3
  import { serialize, parse } from 'cookie';
6
- import { l as levels, g as getEventPrefix, L as Logger, A as AstroIntegrationLogger, manifest } from './manifest_oV2meNKS.mjs';
4
+ 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_tggR3S_9.mjs';
5
+ import { l as levels, g as getEventPrefix, L as Logger, A as AstroIntegrationLogger, manifest } from './manifest_RrmXPEuL.mjs';
7
6
  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_H-6uiAAG.mjs';
9
7
  import 'clsx';
10
8
  import buffer from 'node:buffer';
11
9
  import crypto from 'node:crypto';
12
- import https from 'https';
10
+ import http from 'node:http';
11
+ import https$1 from 'https';
12
+ import enableDestroy from 'server-destroy';
13
13
  import path from 'node:path';
14
- import { fileURLToPath } from 'node:url';
15
- import os from 'os';
14
+ import url from 'node:url';
16
15
  import send from 'send';
17
- import enableDestroy from 'server-destroy';
16
+ import os from 'node:os';
17
+ import https from 'node:https';
18
18
  import { renderers } from './renderers.mjs';
19
19
 
20
20
  function getPathByLocale(locale, locales) {
@@ -84,25 +84,41 @@ function createI18nMiddleware(i18n, base, trailingSlash) {
84
84
  const response = await next();
85
85
  if (response instanceof Response) {
86
86
  const pathnameContainsDefaultLocale = url.pathname.includes(`/${defaultLocale}`);
87
- if (i18n.routing === "prefix-other-locales" && pathnameContainsDefaultLocale) {
88
- const newLocation = url.pathname.replace(`/${defaultLocale}`, "");
89
- response.headers.set("Location", newLocation);
90
- return new Response(null, {
91
- status: 404,
92
- headers: response.headers
93
- });
94
- } else if (i18n.routing === "prefix-always") {
95
- if (url.pathname === base + "/" || url.pathname === base) {
96
- if (trailingSlash === "always") {
97
- return context.redirect(`${appendForwardSlash$1(joinPaths(base, i18n.defaultLocale))}`);
98
- } else {
99
- return context.redirect(`${joinPaths(base, i18n.defaultLocale)}`);
87
+ switch (i18n.routing) {
88
+ case "pathname-prefix-other-locales": {
89
+ if (pathnameContainsDefaultLocale) {
90
+ const newLocation = url.pathname.replace(`/${defaultLocale}`, "");
91
+ response.headers.set("Location", newLocation);
92
+ return new Response(null, {
93
+ status: 404,
94
+ headers: response.headers
95
+ });
96
+ }
97
+ break;
98
+ }
99
+ case "pathname-prefix-always-no-redirect": {
100
+ const isRoot = url.pathname === base + "/" || url.pathname === base;
101
+ if (!(isRoot || pathnameHasLocale(url.pathname, i18n.locales))) {
102
+ return new Response(null, {
103
+ status: 404,
104
+ headers: response.headers
105
+ });
106
+ }
107
+ break;
108
+ }
109
+ case "pathname-prefix-always": {
110
+ if (url.pathname === base + "/" || url.pathname === base) {
111
+ if (trailingSlash === "always") {
112
+ return context.redirect(`${appendForwardSlash$1(joinPaths(base, i18n.defaultLocale))}`);
113
+ } else {
114
+ return context.redirect(`${joinPaths(base, i18n.defaultLocale)}`);
115
+ }
116
+ } else if (!pathnameHasLocale(url.pathname, i18n.locales)) {
117
+ return new Response(null, {
118
+ status: 404,
119
+ headers: response.headers
120
+ });
100
121
  }
101
- } else if (!pathnameHasLocale(url.pathname, i18n.locales)) {
102
- return new Response(null, {
103
- status: 404,
104
- headers: response.headers
105
- });
106
122
  }
107
123
  }
108
124
  if (response.status >= 300 && fallback) {
@@ -124,7 +140,7 @@ function createI18nMiddleware(i18n, base, trailingSlash) {
124
140
  const fallbackLocale = fallback[urlLocale];
125
141
  const pathFallbackLocale = getPathByLocale(fallbackLocale, locales);
126
142
  let newPathname;
127
- if (pathFallbackLocale === defaultLocale && routing === "prefix-other-locales") {
143
+ if (pathFallbackLocale === defaultLocale && routing === "pathname-prefix-other-locales") {
128
144
  newPathname = url.pathname.replace(`/${urlLocale}`, ``);
129
145
  } else {
130
146
  newPathname = url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`);
@@ -168,10 +184,12 @@ class AstroCookies {
168
184
  #request;
169
185
  #requestValues;
170
186
  #outgoing;
187
+ #consumed;
171
188
  constructor(request) {
172
189
  this.#request = request;
173
190
  this.#requestValues = null;
174
191
  this.#outgoing = null;
192
+ this.#consumed = false;
175
193
  }
176
194
  /**
177
195
  * Astro.cookies.delete(key) is used to delete a cookie. Using this method will result
@@ -241,6 +259,13 @@ class AstroCookies {
241
259
  * @param options Options for the cookie, such as the path and security settings.
242
260
  */
243
261
  set(key, value, options) {
262
+ if (this.#consumed) {
263
+ const warning = new Error(
264
+ "Astro.cookies.set() was called after the cookies had already been sent to the browser.\nThis may have happened if this method was called in an imported component.\nPlease make sure that Astro.cookies.set() is only called in the frontmatter of the main page."
265
+ );
266
+ warning.name = "Warning";
267
+ console.warn(warning);
268
+ }
244
269
  let serializedValue;
245
270
  if (typeof value === "string") {
246
271
  serializedValue = value;
@@ -280,6 +305,14 @@ class AstroCookies {
280
305
  yield value[1];
281
306
  }
282
307
  }
308
+ /**
309
+ * Behaves the same as AstroCookies.prototype.headers(),
310
+ * but allows a warning when cookies are set after the instance is consumed.
311
+ */
312
+ static consume(cookies) {
313
+ cookies.#consumed = true;
314
+ return cookies.headers();
315
+ }
283
316
  #ensureParsed(options = void 0) {
284
317
  if (!this.#requestValues) {
285
318
  this.#parse(options);
@@ -324,7 +357,7 @@ function* getSetCookiesFromResponse(response) {
324
357
  if (!cookies) {
325
358
  return [];
326
359
  }
327
- for (const headerValue of cookies.headers()) {
360
+ for (const headerValue of AstroCookies.consume(cookies)) {
328
361
  yield headerValue;
329
362
  }
330
363
  return [];
@@ -410,8 +443,8 @@ function redirectRouteGenerate(redirectRoute, data) {
410
443
  }
411
444
  function redirectRouteStatus(redirectRoute, method = "GET") {
412
445
  const routeData = redirectRoute.redirectRoute;
413
- if (typeof routeData?.redirect === "object") {
414
- return routeData.redirect.status;
446
+ if (routeData && typeof redirectRoute.redirect === "object") {
447
+ return redirectRoute.redirect.status;
415
448
  } else if (method !== "GET") {
416
449
  return 308;
417
450
  }
@@ -714,7 +747,7 @@ function validatePrerenderEndpointCollision(route, mod, params) {
714
747
  }
715
748
  }
716
749
 
717
- const clientLocalsSymbol$2 = Symbol.for("astro.locals");
750
+ const clientLocalsSymbol$1 = Symbol.for("astro.locals");
718
751
  async function createRenderContext(options) {
719
752
  const request = options.request;
720
753
  const pathname = options.pathname ?? new URL(request.url).pathname;
@@ -738,13 +771,13 @@ async function createRenderContext(options) {
738
771
  Object.defineProperty(context, "locals", {
739
772
  enumerable: true,
740
773
  get() {
741
- return Reflect.get(request, clientLocalsSymbol$2);
774
+ return Reflect.get(request, clientLocalsSymbol$1);
742
775
  },
743
776
  set(val) {
744
777
  if (typeof val !== "object") {
745
778
  throw new AstroError(LocalsNotAnObject);
746
779
  } else {
747
- Reflect.set(request, clientLocalsSymbol$2, val);
780
+ Reflect.set(request, clientLocalsSymbol$1, val);
748
781
  }
749
782
  }
750
783
  });
@@ -875,7 +908,7 @@ function computeCurrentLocale(request, locales, routingStrategy, defaultLocale)
875
908
  }
876
909
  }
877
910
  }
878
- if (routingStrategy === "prefix-other-locales") {
911
+ if (routingStrategy === "pathname-prefix-other-locales") {
879
912
  return defaultLocale;
880
913
  }
881
914
  return void 0;
@@ -885,8 +918,8 @@ function createEnvironment(options) {
885
918
  return options;
886
919
  }
887
920
 
888
- const clientAddressSymbol$2 = Symbol.for("astro.clientAddress");
889
- const clientLocalsSymbol$1 = Symbol.for("astro.locals");
921
+ const clientAddressSymbol$3 = Symbol.for("astro.clientAddress");
922
+ const clientLocalsSymbol = Symbol.for("astro.locals");
890
923
  function createAPIContext({
891
924
  request,
892
925
  params,
@@ -946,8 +979,8 @@ function createAPIContext({
946
979
  },
947
980
  url: new URL(request.url),
948
981
  get clientAddress() {
949
- if (clientAddressSymbol$2 in request) {
950
- return Reflect.get(request, clientAddressSymbol$2);
982
+ if (clientAddressSymbol$3 in request) {
983
+ return Reflect.get(request, clientAddressSymbol$3);
951
984
  }
952
985
  if (adapterName) {
953
986
  throw new AstroError({
@@ -959,10 +992,10 @@ function createAPIContext({
959
992
  }
960
993
  },
961
994
  get locals() {
962
- let locals = Reflect.get(request, clientLocalsSymbol$1);
995
+ let locals = Reflect.get(request, clientLocalsSymbol);
963
996
  if (locals === void 0) {
964
997
  locals = {};
965
- Reflect.set(request, clientLocalsSymbol$1, locals);
998
+ Reflect.set(request, clientLocalsSymbol, locals);
966
999
  }
967
1000
  if (typeof locals !== "object") {
968
1001
  throw new AstroError(LocalsNotAnObject);
@@ -974,7 +1007,7 @@ function createAPIContext({
974
1007
  if (typeof val !== "object") {
975
1008
  throw new AstroError(LocalsNotAnObject);
976
1009
  } else {
977
- Reflect.set(request, clientLocalsSymbol$1, val);
1010
+ Reflect.set(request, clientLocalsSymbol, val);
978
1011
  }
979
1012
  }
980
1013
  };
@@ -1089,7 +1122,7 @@ function matchRoute(pathname, manifest) {
1089
1122
  });
1090
1123
  }
1091
1124
 
1092
- const clientAddressSymbol$1 = Symbol.for("astro.clientAddress");
1125
+ const clientAddressSymbol$2 = Symbol.for("astro.clientAddress");
1093
1126
  const responseSentSymbol$1 = Symbol.for("astro.responseSent");
1094
1127
  function getFunctionExpression(slot) {
1095
1128
  if (!slot)
@@ -1195,7 +1228,7 @@ function createResult(args) {
1195
1228
  // @ts-expect-error
1196
1229
  __proto__: astroGlobal,
1197
1230
  get clientAddress() {
1198
- if (!(clientAddressSymbol$1 in request)) {
1231
+ if (!(clientAddressSymbol$2 in request)) {
1199
1232
  if (args.adapterName) {
1200
1233
  throw new AstroError({
1201
1234
  ...ClientAddressNotAvailable,
@@ -1205,7 +1238,7 @@ function createResult(args) {
1205
1238
  throw new AstroError(StaticClientAddressNotAvailable);
1206
1239
  }
1207
1240
  }
1208
- return Reflect.get(request, clientAddressSymbol$1);
1241
+ return Reflect.get(request, clientAddressSymbol$2);
1209
1242
  },
1210
1243
  get cookies() {
1211
1244
  if (cookies) {
@@ -1496,9 +1529,10 @@ class SSRRoutePipeline extends Pipeline {
1496
1529
  }
1497
1530
  }
1498
1531
 
1499
- const clientLocalsSymbol = Symbol.for("astro.locals");
1532
+ const localsSymbol = Symbol.for("astro.locals");
1533
+ const clientAddressSymbol$1 = Symbol.for("astro.clientAddress");
1500
1534
  const responseSentSymbol = Symbol.for("astro.responseSent");
1501
- const STATUS_CODES = /* @__PURE__ */ new Set([404, 500]);
1535
+ const REROUTABLE_STATUS_CODES = /* @__PURE__ */ new Set([404, 500]);
1502
1536
  class App {
1503
1537
  /**
1504
1538
  * The current environment of the application
@@ -1592,7 +1626,15 @@ class App {
1592
1626
  async render(request, routeDataOrOptions, maybeLocals) {
1593
1627
  let routeData;
1594
1628
  let locals;
1595
- if (routeDataOrOptions && ("routeData" in routeDataOrOptions || "locals" in routeDataOrOptions)) {
1629
+ let clientAddress;
1630
+ let addCookieHeader;
1631
+ if (routeDataOrOptions && ("addCookieHeader" in routeDataOrOptions || "clientAddress" in routeDataOrOptions || "locals" in routeDataOrOptions || "routeData" in routeDataOrOptions)) {
1632
+ if ("addCookieHeader" in routeDataOrOptions) {
1633
+ addCookieHeader = routeDataOrOptions.addCookieHeader;
1634
+ }
1635
+ if ("clientAddress" in routeDataOrOptions) {
1636
+ clientAddress = routeDataOrOptions.clientAddress;
1637
+ }
1596
1638
  if ("routeData" in routeDataOrOptions) {
1597
1639
  routeData = routeDataOrOptions.routeData;
1598
1640
  }
@@ -1606,6 +1648,12 @@ class App {
1606
1648
  this.#logRenderOptionsDeprecationWarning();
1607
1649
  }
1608
1650
  }
1651
+ if (locals) {
1652
+ Reflect.set(request, localsSymbol, locals);
1653
+ }
1654
+ if (clientAddress) {
1655
+ Reflect.set(request, clientAddressSymbol$1, clientAddress);
1656
+ }
1609
1657
  if (request.url !== collapseDuplicateSlashes(request.url)) {
1610
1658
  request = new Request(collapseDuplicateSlashes(request.url), request);
1611
1659
  }
@@ -1615,7 +1663,6 @@ class App {
1615
1663
  if (!routeData) {
1616
1664
  return this.#renderError(request, { status: 404 });
1617
1665
  }
1618
- Reflect.set(request, clientLocalsSymbol, locals ?? {});
1619
1666
  const pathname = this.#getPathnameFromRequest(request);
1620
1667
  const defaultStatus = this.#getDefaultStatusCode(routeData, pathname);
1621
1668
  const mod = await this.#getModuleForRoute(routeData);
@@ -1630,7 +1677,7 @@ class App {
1630
1677
  );
1631
1678
  let response;
1632
1679
  try {
1633
- let i18nMiddleware = createI18nMiddleware(
1680
+ const i18nMiddleware = createI18nMiddleware(
1634
1681
  this.#manifest.i18n,
1635
1682
  this.#manifest.base,
1636
1683
  this.#manifest.trailingSlash
@@ -1657,15 +1704,19 @@ class App {
1657
1704
  }
1658
1705
  }
1659
1706
  if (routeData.type === "page" || routeData.type === "redirect") {
1660
- if (STATUS_CODES.has(response.status)) {
1707
+ if (REROUTABLE_STATUS_CODES.has(response.status)) {
1661
1708
  return this.#renderError(request, {
1662
1709
  response,
1663
1710
  status: response.status
1664
1711
  });
1665
1712
  }
1666
- Reflect.set(response, responseSentSymbol, true);
1667
- return response;
1668
1713
  }
1714
+ if (addCookieHeader) {
1715
+ for (const setCookieHeaderValue of App.getSetCookieFromResponse(response)) {
1716
+ response.headers.append("set-cookie", setCookieHeaderValue);
1717
+ }
1718
+ }
1719
+ Reflect.set(response, responseSentSymbol, true);
1669
1720
  return response;
1670
1721
  }
1671
1722
  #logRenderOptionsDeprecationWarning() {
@@ -1680,6 +1731,18 @@ class App {
1680
1731
  setCookieHeaders(response) {
1681
1732
  return getSetCookiesFromResponse(response);
1682
1733
  }
1734
+ /**
1735
+ * Reads all the cookies written by `Astro.cookie.set()` onto the passed response.
1736
+ * For example,
1737
+ * ```ts
1738
+ * for (const cookie_ of App.getSetCookieFromResponse(response)) {
1739
+ * const cookie: string = cookie_
1740
+ * }
1741
+ * ```
1742
+ * @param response The response to read cookies from.
1743
+ * @returns An iterator that yields key-value pairs as equal-sign-separated strings.
1744
+ */
1745
+ static getSetCookieFromResponse = getSetCookiesFromResponse;
1683
1746
  /**
1684
1747
  * Creates the render context of the current route
1685
1748
  */
@@ -1856,6 +1919,23 @@ class App {
1856
1919
  }
1857
1920
  }
1858
1921
 
1922
+ const createOutgoingHttpHeaders = (headers) => {
1923
+ if (!headers) {
1924
+ return void 0;
1925
+ }
1926
+ const nodeHeaders = Object.fromEntries(headers.entries());
1927
+ if (Object.keys(nodeHeaders).length === 0) {
1928
+ return void 0;
1929
+ }
1930
+ if (headers.has("set-cookie")) {
1931
+ const cookieHeaders = headers.getSetCookie();
1932
+ if (cookieHeaders.length > 1) {
1933
+ nodeHeaders["set-cookie"] = cookieHeaders;
1934
+ }
1935
+ }
1936
+ return nodeHeaders;
1937
+ };
1938
+
1859
1939
  function apply() {
1860
1940
  if (!globalThis.crypto) {
1861
1941
  Object.defineProperty(globalThis, "crypto", {
@@ -1870,26 +1950,92 @@ function apply() {
1870
1950
  }
1871
1951
 
1872
1952
  const clientAddressSymbol = Symbol.for("astro.clientAddress");
1873
- function createRequestFromNodeRequest(req, options) {
1874
- const protocol = req.socket instanceof TLSSocket || req.headers["x-forwarded-proto"] === "https" ? "https" : "http";
1875
- const hostname = req.headers.host || req.headers[":authority"];
1876
- const url = `${protocol}://${hostname}${req.url}`;
1877
- const headers = makeRequestHeaders(req);
1878
- const method = req.method || "GET";
1879
- let bodyProps = {};
1880
- const bodyAllowed = method !== "HEAD" && method !== "GET" && !options?.emptyBody;
1881
- if (bodyAllowed) {
1882
- bodyProps = makeRequestBody(req);
1883
- }
1884
- const request = new Request(url, {
1885
- method,
1886
- headers,
1887
- ...bodyProps
1888
- });
1889
- if (req.socket?.remoteAddress) {
1890
- Reflect.set(request, clientAddressSymbol, req.socket.remoteAddress);
1953
+ class NodeApp extends App {
1954
+ match(req) {
1955
+ if (!(req instanceof Request)) {
1956
+ req = NodeApp.createRequest(req, {
1957
+ skipBody: true
1958
+ });
1959
+ }
1960
+ return super.match(req);
1961
+ }
1962
+ render(req, routeDataOrOptions, maybeLocals) {
1963
+ if (!(req instanceof Request)) {
1964
+ req = NodeApp.createRequest(req);
1965
+ }
1966
+ return super.render(req, routeDataOrOptions, maybeLocals);
1967
+ }
1968
+ /**
1969
+ * Converts a NodeJS IncomingMessage into a web standard Request.
1970
+ * ```js
1971
+ * import { NodeApp } from 'astro/app/node';
1972
+ * import { createServer } from 'node:http';
1973
+ *
1974
+ * const server = createServer(async (req, res) => {
1975
+ * const request = NodeApp.createRequest(req);
1976
+ * const response = await app.render(request);
1977
+ * await NodeApp.writeResponse(response, res);
1978
+ * })
1979
+ * ```
1980
+ */
1981
+ static createRequest(req, { skipBody = false } = {}) {
1982
+ const protocol = req.headers["x-forwarded-proto"] ?? ("encrypted" in req.socket && req.socket.encrypted ? "https" : "http");
1983
+ const hostname = req.headers.host || req.headers[":authority"];
1984
+ const url = `${protocol}://${hostname}${req.url}`;
1985
+ const options = {
1986
+ method: req.method || "GET",
1987
+ headers: makeRequestHeaders(req)
1988
+ };
1989
+ const bodyAllowed = options.method !== "HEAD" && options.method !== "GET" && skipBody === false;
1990
+ if (bodyAllowed) {
1991
+ Object.assign(options, makeRequestBody(req));
1992
+ }
1993
+ const request = new Request(url, options);
1994
+ if (req.socket?.remoteAddress) {
1995
+ Reflect.set(request, clientAddressSymbol, req.socket.remoteAddress);
1996
+ }
1997
+ return request;
1998
+ }
1999
+ /**
2000
+ * Streams a web-standard Response into a NodeJS Server Response.
2001
+ * ```js
2002
+ * import { NodeApp } from 'astro/app/node';
2003
+ * import { createServer } from 'node:http';
2004
+ *
2005
+ * const server = createServer(async (req, res) => {
2006
+ * const request = NodeApp.createRequest(req);
2007
+ * const response = await app.render(request);
2008
+ * await NodeApp.writeResponse(response, res);
2009
+ * })
2010
+ * ```
2011
+ * @param source WhatWG Response
2012
+ * @param destination NodeJS ServerResponse
2013
+ */
2014
+ static async writeResponse(source, destination) {
2015
+ const { status, headers, body } = source;
2016
+ destination.writeHead(status, createOutgoingHttpHeaders(headers));
2017
+ if (body) {
2018
+ try {
2019
+ const reader = body.getReader();
2020
+ destination.on("close", () => {
2021
+ reader.cancel().catch((err) => {
2022
+ console.error(
2023
+ `There was an uncaught error in the middle of the stream while rendering ${destination.req.url}.`,
2024
+ err
2025
+ );
2026
+ });
2027
+ });
2028
+ let result = await reader.read();
2029
+ while (!result.done) {
2030
+ destination.write(result.value);
2031
+ result = await reader.read();
2032
+ }
2033
+ } catch {
2034
+ destination.write("Internal server error");
2035
+ }
2036
+ }
2037
+ destination.end();
1891
2038
  }
1892
- return request;
1893
2039
  }
1894
2040
  function makeRequestHeaders(req) {
1895
2041
  const headers = new Headers();
@@ -1930,132 +2076,117 @@ function asyncIterableToBodyProps(iterable) {
1930
2076
  // The duplex property is required when using a ReadableStream or async
1931
2077
  // iterable for the body. The type definitions do not include the duplex
1932
2078
  // property because they are not up-to-date.
1933
- // @ts-expect-error
1934
2079
  duplex: "half"
1935
2080
  };
1936
2081
  }
1937
- class NodeApp extends App {
1938
- match(req) {
1939
- if (!(req instanceof Request)) {
1940
- req = createRequestFromNodeRequest(req, {
1941
- emptyBody: true
2082
+
2083
+ function createAppHandler(app) {
2084
+ return async (req, res, next, locals) => {
2085
+ const request = NodeApp.createRequest(req);
2086
+ const routeData = app.match(request);
2087
+ if (routeData) {
2088
+ const response = await app.render(request, {
2089
+ addCookieHeader: true,
2090
+ locals,
2091
+ routeData
1942
2092
  });
2093
+ await NodeApp.writeResponse(response, res);
2094
+ } else if (next) {
2095
+ return next();
2096
+ } else {
2097
+ const response = await app.render(req);
2098
+ await NodeApp.writeResponse(response, res);
1943
2099
  }
1944
- return super.match(req);
1945
- }
1946
- render(req, routeDataOrOptions, maybeLocals) {
1947
- if (!(req instanceof Request)) {
1948
- req = createRequestFromNodeRequest(req);
1949
- }
1950
- return super.render(req, routeDataOrOptions, maybeLocals);
1951
- }
2100
+ };
1952
2101
  }
1953
2102
 
1954
- const createOutgoingHttpHeaders = (headers) => {
1955
- if (!headers) {
1956
- return void 0;
1957
- }
1958
- const nodeHeaders = Object.fromEntries(headers.entries());
1959
- if (Object.keys(nodeHeaders).length === 0) {
1960
- return void 0;
1961
- }
1962
- if (headers.has("set-cookie")) {
1963
- const cookieHeaders = headers.getSetCookie();
1964
- if (cookieHeaders.length > 1) {
1965
- nodeHeaders["set-cookie"] = cookieHeaders;
1966
- }
1967
- }
1968
- return nodeHeaders;
1969
- };
1970
-
1971
- function nodeMiddleware_default(app, mode) {
1972
- return async function(...args) {
1973
- let error = null;
1974
- let locals;
1975
- let [req, res, next] = args;
1976
- if (mode === "middleware") {
1977
- let { [3]: _locals } = args;
1978
- locals = _locals;
1979
- }
1980
- if (args[0] instanceof Error) {
1981
- [error, req, res, next] = args;
1982
- if (mode === "middleware") {
1983
- let { [4]: _locals } = args;
1984
- locals = _locals;
1985
- }
1986
- if (error) {
1987
- if (next) {
1988
- return next(error);
1989
- } else {
1990
- throw error;
2103
+ function createStaticHandler(app, options) {
2104
+ const client = resolveClientDir(options);
2105
+ return (req, res, ssr) => {
2106
+ if (req.url) {
2107
+ let pathname = app.removeBase(req.url);
2108
+ pathname = decodeURI(new URL(pathname, "http://host").pathname);
2109
+ const stream = send(req, pathname, {
2110
+ root: client,
2111
+ dotfiles: pathname.startsWith("/.well-known/") ? "allow" : "deny"
2112
+ });
2113
+ let forwardError = false;
2114
+ stream.on("error", (err) => {
2115
+ if (forwardError) {
2116
+ console.error(err.toString());
2117
+ res.writeHead(500);
2118
+ res.end("Internal server error");
2119
+ return;
1991
2120
  }
1992
- }
1993
- }
1994
- const logger = app.getAdapterLogger();
1995
- try {
1996
- const routeData = app.match(req);
1997
- if (routeData) {
1998
- try {
1999
- const response = await app.render(req, { routeData, locals });
2000
- await writeWebResponse(app, res, response, logger);
2001
- } catch (err) {
2002
- if (next) {
2003
- next(err);
2004
- } else {
2005
- throw err;
2006
- }
2121
+ ssr();
2122
+ });
2123
+ stream.on("headers", (_res) => {
2124
+ if (pathname.startsWith(`/${options.assets}/`)) {
2125
+ _res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
2007
2126
  }
2008
- } else if (next) {
2009
- return next();
2010
- } else {
2011
- const response = await app.render(req);
2012
- await writeWebResponse(app, res, response, logger);
2013
- }
2014
- } catch (err) {
2015
- logger.error(`Could not render ${req.url}`);
2016
- console.error(err);
2017
- if (!res.headersSent) {
2018
- res.writeHead(500, `Server error`);
2019
- res.end();
2020
- }
2127
+ });
2128
+ stream.on("directory", () => {
2129
+ let location;
2130
+ if (req.url.includes("?")) {
2131
+ const [url1 = "", search] = req.url.split("?");
2132
+ location = `${url1}/?${search}`;
2133
+ } else {
2134
+ location = appendForwardSlash(req.url);
2135
+ }
2136
+ res.statusCode = 301;
2137
+ res.setHeader("Location", location);
2138
+ res.end(location);
2139
+ });
2140
+ stream.on("file", () => {
2141
+ forwardError = true;
2142
+ });
2143
+ stream.pipe(res);
2144
+ } else {
2145
+ ssr();
2021
2146
  }
2022
2147
  };
2023
2148
  }
2024
- async function writeWebResponse(app, res, webResponse, logger) {
2025
- const { status, headers, body } = webResponse;
2026
- if (app.setCookieHeaders) {
2027
- const setCookieHeaders = Array.from(app.setCookieHeaders(webResponse));
2028
- if (setCookieHeaders.length) {
2029
- for (const setCookieHeader of setCookieHeaders) {
2030
- headers.append("set-cookie", setCookieHeader);
2031
- }
2032
- }
2149
+ function resolveClientDir(options) {
2150
+ const clientURLRaw = new URL(options.client);
2151
+ const serverURLRaw = new URL(options.server);
2152
+ const rel = path.relative(url.fileURLToPath(serverURLRaw), url.fileURLToPath(clientURLRaw));
2153
+ const serverEntryURL = new URL(import.meta.url);
2154
+ const clientURL = new URL(appendForwardSlash(rel), serverEntryURL);
2155
+ const client = url.fileURLToPath(clientURL);
2156
+ return client;
2157
+ }
2158
+ function appendForwardSlash(pth) {
2159
+ return pth.endsWith("/") ? pth : pth + "/";
2160
+ }
2161
+
2162
+ async function logListeningOn(logger, server, options) {
2163
+ await new Promise((resolve) => server.once("listening", resolve));
2164
+ const protocol = server instanceof https.Server ? "https" : "http";
2165
+ const host = getResolvedHostForHttpServer(
2166
+ process.env.HOST !== void 0 && process.env.HOST !== "" ? process.env.HOST : options.host
2167
+ );
2168
+ const { port } = server.address();
2169
+ const address = getNetworkAddress(protocol, host, port);
2170
+ if (host === void 0) {
2171
+ logger.info(
2172
+ `Server listening on
2173
+ local: ${address.local[0]}
2174
+ network: ${address.network[0]}
2175
+ `
2176
+ );
2177
+ } else {
2178
+ logger.info(`Server listening on ${address.local[0]}`);
2033
2179
  }
2034
- const nodeHeaders = createOutgoingHttpHeaders(headers);
2035
- res.writeHead(status, nodeHeaders);
2036
- if (body) {
2037
- try {
2038
- const reader = body.getReader();
2039
- res.on("close", () => {
2040
- reader.cancel().catch((err) => {
2041
- logger.error(
2042
- `There was an uncaught error in the middle of the stream while rendering ${res.req.url}.`
2043
- );
2044
- console.error(err);
2045
- });
2046
- });
2047
- let result = await reader.read();
2048
- while (!result.done) {
2049
- res.write(result.value);
2050
- result = await reader.read();
2051
- }
2052
- } catch {
2053
- res.write("Internal server error");
2054
- }
2180
+ }
2181
+ function getResolvedHostForHttpServer(host) {
2182
+ if (host === false) {
2183
+ return "localhost";
2184
+ } else if (host === true) {
2185
+ return void 0;
2186
+ } else {
2187
+ return host;
2055
2188
  }
2056
- res.end();
2057
2189
  }
2058
-
2059
2190
  const wildcardHosts = /* @__PURE__ */ new Set(["0.0.0.0", "::", "0000:0000:0000:0000:0000:0000:0000:0000"]);
2060
2191
  function getNetworkAddress(protocol = "http", hostname, port, base) {
2061
2192
  const NetworkAddress = {
@@ -2083,71 +2214,39 @@ function getNetworkAddress(protocol = "http", hostname, port, base) {
2083
2214
  return NetworkAddress;
2084
2215
  }
2085
2216
 
2086
- function parsePathname(pathname, host, port) {
2087
- try {
2088
- const urlPathname = new URL(pathname, `http://${host}:${port}`).pathname;
2089
- return decodeURI(encodeURI(urlPathname));
2090
- } catch (err) {
2091
- return void 0;
2217
+ function standalone(app, options) {
2218
+ const port = process.env.PORT ? Number(process.env.PORT) : options.port ?? 8080;
2219
+ const hostOptions = typeof options.host === "boolean" ? "localhost" : options.host;
2220
+ const host = process.env.HOST ?? hostOptions;
2221
+ const handler = createStandaloneHandler(app, options);
2222
+ const server = createServer(handler, host, port);
2223
+ server.server.listen(port, host);
2224
+ if (process.env.ASTRO_NODE_LOGGING !== "disabled") {
2225
+ logListeningOn(app.getAdapterLogger(), server.server, options);
2092
2226
  }
2227
+ return {
2228
+ server,
2229
+ done: server.closed()
2230
+ };
2093
2231
  }
2094
- function createServer({ client, port, host, removeBase, assets }, handler) {
2095
- const assetsPrefix = `/${assets}/`;
2096
- function isImmutableAsset(pathname) {
2097
- return pathname.startsWith(assetsPrefix);
2098
- }
2099
- const listener = (req, res) => {
2100
- if (req.url) {
2101
- let pathname = removeBase(req.url);
2102
- pathname = pathname[0] === "/" ? pathname : "/" + pathname;
2103
- const encodedURI = parsePathname(pathname, host, port);
2104
- if (!encodedURI) {
2105
- res.writeHead(400);
2106
- res.end("Bad request.");
2107
- return res;
2108
- }
2109
- const stream = send(req, encodedURI, {
2110
- root: fileURLToPath(client),
2111
- dotfiles: pathname.startsWith("/.well-known/") ? "allow" : "deny"
2112
- });
2113
- let forwardError = false;
2114
- stream.on("error", (err) => {
2115
- if (forwardError) {
2116
- console.error(err.toString());
2117
- res.writeHead(500);
2118
- res.end("Internal server error");
2119
- return;
2120
- }
2121
- handler(req, res);
2122
- });
2123
- stream.on("headers", (_res) => {
2124
- if (isImmutableAsset(encodedURI)) {
2125
- _res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
2126
- }
2127
- });
2128
- stream.on("directory", () => {
2129
- let location;
2130
- if (req.url.includes("?")) {
2131
- const [url = "", search] = req.url.split("?");
2132
- location = `${url}/?${search}`;
2133
- } else {
2134
- location = req.url + "/";
2135
- }
2136
- res.statusCode = 301;
2137
- res.setHeader("Location", location);
2138
- res.end(location);
2139
- });
2140
- stream.on("file", () => {
2141
- forwardError = true;
2142
- });
2143
- stream.pipe(res);
2144
- } else {
2145
- handler(req, res);
2232
+ function createStandaloneHandler(app, options) {
2233
+ const appHandler = createAppHandler(app);
2234
+ const staticHandler = createStaticHandler(app, options);
2235
+ return (req, res) => {
2236
+ try {
2237
+ decodeURI(req.url);
2238
+ } catch {
2239
+ res.writeHead(400);
2240
+ res.end("Bad request.");
2241
+ return;
2146
2242
  }
2243
+ staticHandler(req, res, () => appHandler(req, res));
2147
2244
  };
2245
+ }
2246
+ function createServer(listener, host, port) {
2148
2247
  let httpServer;
2149
2248
  if (process.env.SERVER_CERT_PATH && process.env.SERVER_KEY_PATH) {
2150
- httpServer = https.createServer(
2249
+ httpServer = https$1.createServer(
2151
2250
  {
2152
2251
  key: fs.readFileSync(process.env.SERVER_KEY_PATH),
2153
2252
  cert: fs.readFileSync(process.env.SERVER_CERT_PATH)
@@ -2157,82 +2256,52 @@ function createServer({ client, port, host, removeBase, assets }, handler) {
2157
2256
  } else {
2158
2257
  httpServer = http.createServer(listener);
2159
2258
  }
2160
- httpServer.listen(port, host);
2161
2259
  enableDestroy(httpServer);
2162
2260
  const closed = new Promise((resolve, reject) => {
2163
2261
  httpServer.addListener("close", resolve);
2164
2262
  httpServer.addListener("error", reject);
2165
2263
  });
2166
- return {
2264
+ const previewable = {
2167
2265
  host,
2168
2266
  port,
2169
2267
  closed() {
2170
2268
  return closed;
2171
2269
  },
2172
- server: httpServer,
2173
- stop: async () => {
2270
+ async stop() {
2174
2271
  await new Promise((resolve, reject) => {
2175
2272
  httpServer.destroy((err) => err ? reject(err) : resolve(void 0));
2176
2273
  });
2177
2274
  }
2178
2275
  };
2179
- }
2180
-
2181
- function resolvePaths(options) {
2182
- const clientURLRaw = new URL(options.client);
2183
- const serverURLRaw = new URL(options.server);
2184
- const rel = path.relative(fileURLToPath(serverURLRaw), fileURLToPath(clientURLRaw));
2185
- const serverEntryURL = new URL(import.meta.url);
2186
- const clientURL = new URL(appendForwardSlash(rel), serverEntryURL);
2187
2276
  return {
2188
- client: clientURL
2277
+ server: httpServer,
2278
+ ...previewable
2189
2279
  };
2190
2280
  }
2191
- function appendForwardSlash(pth) {
2192
- return pth.endsWith("/") ? pth : pth + "/";
2193
- }
2194
- function getResolvedHostForHttpServer(host) {
2195
- if (host === false) {
2196
- return "127.0.0.1";
2197
- } else if (host === true) {
2198
- return void 0;
2199
- } else {
2200
- return host;
2201
- }
2202
- }
2203
- function startServer$1(app, options) {
2281
+
2282
+ function createMiddleware(app) {
2283
+ const handler = createAppHandler(app);
2204
2284
  const logger = app.getAdapterLogger();
2205
- const port = process.env.PORT ? Number(process.env.PORT) : options.port ?? 8080;
2206
- const { client } = resolvePaths(options);
2207
- const handler = nodeMiddleware_default(app, options.mode);
2208
- const host = getResolvedHostForHttpServer(
2209
- process.env.HOST !== void 0 && process.env.HOST !== "" ? process.env.HOST : options.host
2210
- );
2211
- const server = createServer(
2212
- {
2213
- client,
2214
- port,
2215
- host,
2216
- removeBase: app.removeBase.bind(app),
2217
- assets: options.assets
2218
- },
2219
- handler
2220
- );
2221
- const protocol = server.server instanceof https.Server ? "https" : "http";
2222
- const address = getNetworkAddress(protocol, host, port);
2223
- if (host === void 0) {
2224
- logger.info(
2225
- `Server listening on
2226
- local: ${address.local[0]}
2227
- network: ${address.network[0]}
2228
- `
2229
- );
2230
- } else {
2231
- logger.info(`Server listening on ${address.local[0]}`);
2232
- }
2233
- return {
2234
- server,
2235
- done: server.closed()
2285
+ return async function(...args) {
2286
+ const [req, res, next, locals] = args;
2287
+ if (req instanceof Error) {
2288
+ const error = req;
2289
+ if (next) {
2290
+ return next(error);
2291
+ } else {
2292
+ throw error;
2293
+ }
2294
+ }
2295
+ try {
2296
+ await handler(req, res, next, locals);
2297
+ } catch (err) {
2298
+ logger.error(`Could not render ${req.url}`);
2299
+ console.error(err);
2300
+ if (!res.headersSent) {
2301
+ res.writeHead(500, `Server error`);
2302
+ res.end();
2303
+ }
2304
+ }
2236
2305
  };
2237
2306
  }
2238
2307
 
@@ -2241,8 +2310,8 @@ function createExports(manifest, options) {
2241
2310
  const app = new NodeApp(manifest);
2242
2311
  return {
2243
2312
  options,
2244
- handler: nodeMiddleware_default(app, options.mode),
2245
- startServer: () => startServer$1(app, options)
2313
+ handler: options.mode === "middleware" ? createMiddleware(app) : createStandaloneHandler(app, options),
2314
+ startServer: () => standalone(app, options)
2246
2315
  };
2247
2316
  }
2248
2317
  function start(manifest, options) {
@@ -2250,7 +2319,7 @@ function start(manifest, options) {
2250
2319
  return;
2251
2320
  }
2252
2321
  const app = new NodeApp(manifest);
2253
- startServer$1(app, options);
2322
+ standalone(app, options);
2254
2323
  }
2255
2324
 
2256
2325
  const adapter = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
@@ -2259,12 +2328,12 @@ const adapter = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
2259
2328
  start
2260
2329
  }, Symbol.toStringTag, { value: 'Module' }));
2261
2330
 
2262
- const _page0 = () => import('./chunks/node_-eQO2yOn.mjs');
2263
- const _page1 = () => import('./chunks/~fallback_M-xiy2GE.mjs');
2264
- const _page2 = () => import('./chunks/_page__WXDIwV7g.mjs');
2265
- const _page3 = () => import('./chunks/index_eXlHIU83.mjs');
2266
- const _page4 = () => import('./chunks/account_DOT2RzND.mjs');
2267
- const _page5 = () => import('./chunks/_.._D6rq0cLa.mjs');const pageMap = new Map([["../../node_modules/.pnpm/astro@4.1.1_@types+node@18.19.5_typescript@5.2.2/node_modules/astro/dist/assets/endpoint/node.js", _page0],["src/pages/~fallback.astro", _page1],["src/pages/blog/[page].astro", _page2],["src/pages/app/index.astro", _page3],["src/pages/app/account.astro", _page4],["src/pages/[...slug].astro", _page5]]);
2331
+ const _page0 = () => import('./chunks/node_kUJIRL0c.mjs');
2332
+ const _page1 = () => import('./chunks/index_e3ytAL8v.mjs');
2333
+ const _page2 = () => import('./chunks/account_jmelxnlw.mjs');
2334
+ const _page3 = () => import('./chunks/_page__lWVlZyRe.mjs');
2335
+ const _page4 = () => import('./chunks/~fallback_EZqiEAFE.mjs');
2336
+ const _page5 = () => import('./chunks/_.._h5R83hoK.mjs');const pageMap = new Map([["../../node_modules/.pnpm/astro@4.2.1_@types+node@18.19.7_typescript@5.2.2/node_modules/astro/dist/assets/endpoint/node.js", _page0],["src/pages/app/index.astro", _page1],["src/pages/app/account.astro", _page2],["src/pages/blog/[page].astro", _page3],["src/pages/~fallback.astro", _page4],["src/pages/[...slug].astro", _page5]]);
2268
2337
  const _manifest = Object.assign(manifest, {
2269
2338
  pageMap,
2270
2339
  renderers,