@gatanot/qualia_web 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/build/client/_app/immutable/assets/0.BlmLthUu.css +1 -0
  2. package/build/client/_app/immutable/assets/0.BlmLthUu.css.br +0 -0
  3. package/build/client/_app/immutable/assets/0.BlmLthUu.css.gz +0 -0
  4. package/build/client/_app/immutable/assets/2.C6F1hpzI.css +1 -0
  5. package/build/client/_app/immutable/assets/2.C6F1hpzI.css.br +0 -0
  6. package/build/client/_app/immutable/assets/2.C6F1hpzI.css.gz +0 -0
  7. package/build/client/_app/immutable/assets/3.D8sLuVpx.css +1 -0
  8. package/build/client/_app/immutable/assets/3.D8sLuVpx.css.br +0 -0
  9. package/build/client/_app/immutable/assets/3.D8sLuVpx.css.gz +0 -0
  10. package/build/client/_app/immutable/assets/4.1xWrYHn4.css +1 -0
  11. package/build/client/_app/immutable/assets/4.1xWrYHn4.css.br +0 -0
  12. package/build/client/_app/immutable/assets/4.1xWrYHn4.css.gz +0 -0
  13. package/build/client/_app/immutable/assets/5.K6sy6bnZ.css +1 -0
  14. package/build/client/_app/immutable/assets/5.K6sy6bnZ.css.br +0 -0
  15. package/build/client/_app/immutable/assets/5.K6sy6bnZ.css.gz +0 -0
  16. package/build/client/_app/immutable/assets/ChatInput.CmxPxwkj.css +1 -0
  17. package/build/client/_app/immutable/assets/ChatInput.CmxPxwkj.css.br +0 -0
  18. package/build/client/_app/immutable/assets/ChatInput.CmxPxwkj.css.gz +0 -0
  19. package/build/client/_app/immutable/assets/KaTeX_AMS-Regular.BQhdFMY1.woff2 +0 -0
  20. package/build/client/_app/immutable/assets/KaTeX_AMS-Regular.DMm9YOAa.woff +0 -0
  21. package/build/client/_app/immutable/assets/KaTeX_AMS-Regular.DRggAlZN.ttf +0 -0
  22. package/build/client/_app/immutable/assets/KaTeX_Caligraphic-Bold.ATXxdsX0.ttf +0 -0
  23. package/build/client/_app/immutable/assets/KaTeX_Caligraphic-Bold.BEiXGLvX.woff +0 -0
  24. package/build/client/_app/immutable/assets/KaTeX_Caligraphic-Bold.Dq_IR9rO.woff2 +0 -0
  25. package/build/client/_app/immutable/assets/KaTeX_Caligraphic-Regular.CTRA-rTL.woff +0 -0
  26. package/build/client/_app/immutable/assets/KaTeX_Caligraphic-Regular.Di6jR-x-.woff2 +0 -0
  27. package/build/client/_app/immutable/assets/KaTeX_Caligraphic-Regular.wX97UBjC.ttf +0 -0
  28. package/build/client/_app/immutable/assets/KaTeX_Fraktur-Bold.BdnERNNW.ttf +0 -0
  29. package/build/client/_app/immutable/assets/KaTeX_Fraktur-Bold.BsDP51OF.woff +0 -0
  30. package/build/client/_app/immutable/assets/KaTeX_Fraktur-Bold.CL6g_b3V.woff2 +0 -0
  31. package/build/client/_app/immutable/assets/KaTeX_Fraktur-Regular.CB_wures.ttf +0 -0
  32. package/build/client/_app/immutable/assets/KaTeX_Fraktur-Regular.CTYiF6lA.woff2 +0 -0
  33. package/build/client/_app/immutable/assets/KaTeX_Fraktur-Regular.Dxdc4cR9.woff +0 -0
  34. package/build/client/_app/immutable/assets/KaTeX_Main-Bold.Cx986IdX.woff2 +0 -0
  35. package/build/client/_app/immutable/assets/KaTeX_Main-Bold.Jm3AIy58.woff +0 -0
  36. package/build/client/_app/immutable/assets/KaTeX_Main-Bold.waoOVXN0.ttf +0 -0
  37. package/build/client/_app/immutable/assets/KaTeX_Main-BoldItalic.DxDJ3AOS.woff2 +0 -0
  38. package/build/client/_app/immutable/assets/KaTeX_Main-BoldItalic.DzxPMmG6.ttf +0 -0
  39. package/build/client/_app/immutable/assets/KaTeX_Main-BoldItalic.SpSLRI95.woff +0 -0
  40. package/build/client/_app/immutable/assets/KaTeX_Main-Italic.3WenGoN9.ttf +0 -0
  41. package/build/client/_app/immutable/assets/KaTeX_Main-Italic.BMLOBm91.woff +0 -0
  42. package/build/client/_app/immutable/assets/KaTeX_Main-Italic.NWA7e6Wa.woff2 +0 -0
  43. package/build/client/_app/immutable/assets/KaTeX_Main-Regular.B22Nviop.woff2 +0 -0
  44. package/build/client/_app/immutable/assets/KaTeX_Main-Regular.Dr94JaBh.woff +0 -0
  45. package/build/client/_app/immutable/assets/KaTeX_Main-Regular.ypZvNtVU.ttf +0 -0
  46. package/build/client/_app/immutable/assets/KaTeX_Math-BoldItalic.B3XSjfu4.ttf +0 -0
  47. package/build/client/_app/immutable/assets/KaTeX_Math-BoldItalic.CZnvNsCZ.woff2 +0 -0
  48. package/build/client/_app/immutable/assets/KaTeX_Math-BoldItalic.iY-2wyZ7.woff +0 -0
  49. package/build/client/_app/immutable/assets/KaTeX_Math-Italic.DA0__PXp.woff +0 -0
  50. package/build/client/_app/immutable/assets/KaTeX_Math-Italic.flOr_0UB.ttf +0 -0
  51. package/build/client/_app/immutable/assets/KaTeX_Math-Italic.t53AETM-.woff2 +0 -0
  52. package/build/client/_app/immutable/assets/KaTeX_SansSerif-Bold.CFMepnvq.ttf +0 -0
  53. package/build/client/_app/immutable/assets/KaTeX_SansSerif-Bold.D1sUS0GD.woff2 +0 -0
  54. package/build/client/_app/immutable/assets/KaTeX_SansSerif-Bold.DbIhKOiC.woff +0 -0
  55. package/build/client/_app/immutable/assets/KaTeX_SansSerif-Italic.C3H0VqGB.woff2 +0 -0
  56. package/build/client/_app/immutable/assets/KaTeX_SansSerif-Italic.DN2j7dab.woff +0 -0
  57. package/build/client/_app/immutable/assets/KaTeX_SansSerif-Italic.YYjJ1zSn.ttf +0 -0
  58. package/build/client/_app/immutable/assets/KaTeX_SansSerif-Regular.BNo7hRIc.ttf +0 -0
  59. package/build/client/_app/immutable/assets/KaTeX_SansSerif-Regular.CS6fqUqJ.woff +0 -0
  60. package/build/client/_app/immutable/assets/KaTeX_SansSerif-Regular.DDBCnlJ7.woff2 +0 -0
  61. package/build/client/_app/immutable/assets/KaTeX_Script-Regular.C5JkGWo-.ttf +0 -0
  62. package/build/client/_app/immutable/assets/KaTeX_Script-Regular.D3wIWfF6.woff2 +0 -0
  63. package/build/client/_app/immutable/assets/KaTeX_Script-Regular.D5yQViql.woff +0 -0
  64. package/build/client/_app/immutable/assets/KaTeX_Size1-Regular.C195tn64.woff +0 -0
  65. package/build/client/_app/immutable/assets/KaTeX_Size1-Regular.Dbsnue_I.ttf +0 -0
  66. package/build/client/_app/immutable/assets/KaTeX_Size1-Regular.mCD8mA8B.woff2 +0 -0
  67. package/build/client/_app/immutable/assets/KaTeX_Size2-Regular.B7gKUWhC.ttf +0 -0
  68. package/build/client/_app/immutable/assets/KaTeX_Size2-Regular.Dy4dx90m.woff2 +0 -0
  69. package/build/client/_app/immutable/assets/KaTeX_Size2-Regular.oD1tc_U0.woff +0 -0
  70. package/build/client/_app/immutable/assets/KaTeX_Size3-Regular.CTq5MqoE.woff +0 -0
  71. package/build/client/_app/immutable/assets/KaTeX_Size3-Regular.DgpXs0kz.ttf +0 -0
  72. package/build/client/_app/immutable/assets/KaTeX_Size4-Regular.BF-4gkZK.woff +0 -0
  73. package/build/client/_app/immutable/assets/KaTeX_Size4-Regular.DWFBv043.ttf +0 -0
  74. package/build/client/_app/immutable/assets/KaTeX_Size4-Regular.Dl5lxZxV.woff2 +0 -0
  75. package/build/client/_app/immutable/assets/KaTeX_Typewriter-Regular.C0xS9mPB.woff +0 -0
  76. package/build/client/_app/immutable/assets/KaTeX_Typewriter-Regular.CO6r4hn1.woff2 +0 -0
  77. package/build/client/_app/immutable/assets/KaTeX_Typewriter-Regular.D3Ib7_Hf.ttf +0 -0
  78. package/build/client/_app/immutable/chunks/B39M1lOz.js +3 -0
  79. package/build/client/_app/immutable/chunks/B39M1lOz.js.br +0 -0
  80. package/build/client/_app/immutable/chunks/B39M1lOz.js.gz +0 -0
  81. package/build/client/_app/immutable/chunks/BMcRbUT8.js +3 -0
  82. package/build/client/_app/immutable/chunks/BMcRbUT8.js.br +0 -0
  83. package/build/client/_app/immutable/chunks/BMcRbUT8.js.gz +0 -0
  84. package/build/client/_app/immutable/chunks/BN2zEB6w.js +1 -0
  85. package/build/client/_app/immutable/chunks/BN2zEB6w.js.br +0 -0
  86. package/build/client/_app/immutable/chunks/BN2zEB6w.js.gz +0 -0
  87. package/build/client/_app/immutable/chunks/BVDlhZK_.js +1 -0
  88. package/build/client/_app/immutable/chunks/BVDlhZK_.js.br +2 -0
  89. package/build/client/_app/immutable/chunks/BVDlhZK_.js.gz +0 -0
  90. package/build/client/_app/immutable/chunks/CxmPiQW9.js +1 -0
  91. package/build/client/_app/immutable/chunks/CxmPiQW9.js.br +0 -0
  92. package/build/client/_app/immutable/chunks/CxmPiQW9.js.gz +0 -0
  93. package/build/client/_app/immutable/chunks/DAIlYrs_.js +1 -0
  94. package/build/client/_app/immutable/chunks/DAIlYrs_.js.br +0 -0
  95. package/build/client/_app/immutable/chunks/DAIlYrs_.js.gz +0 -0
  96. package/build/client/_app/immutable/chunks/Ir23lSxH.js +329 -0
  97. package/build/client/_app/immutable/chunks/Ir23lSxH.js.br +0 -0
  98. package/build/client/_app/immutable/chunks/Ir23lSxH.js.gz +0 -0
  99. package/build/client/_app/immutable/chunks/gZTJ0hjf.js +1 -0
  100. package/build/client/_app/immutable/chunks/gZTJ0hjf.js.br +0 -0
  101. package/build/client/_app/immutable/chunks/gZTJ0hjf.js.gz +0 -0
  102. package/build/client/_app/immutable/chunks/idCMFvY6.js +1 -0
  103. package/build/client/_app/immutable/chunks/idCMFvY6.js.br +2 -0
  104. package/build/client/_app/immutable/chunks/idCMFvY6.js.gz +0 -0
  105. package/build/client/_app/immutable/chunks/kNaey6uv.js +1 -0
  106. package/build/client/_app/immutable/chunks/kNaey6uv.js.br +0 -0
  107. package/build/client/_app/immutable/chunks/kNaey6uv.js.gz +0 -0
  108. package/build/client/_app/immutable/chunks/xihTtKlq.js +1 -0
  109. package/build/client/_app/immutable/chunks/xihTtKlq.js.br +1 -0
  110. package/build/client/_app/immutable/chunks/xihTtKlq.js.gz +0 -0
  111. package/build/client/_app/immutable/entry/app.CAKAEcgA.js +2 -0
  112. package/build/client/_app/immutable/entry/app.CAKAEcgA.js.br +0 -0
  113. package/build/client/_app/immutable/entry/app.CAKAEcgA.js.gz +0 -0
  114. package/build/client/_app/immutable/entry/start.BSM2k8tg.js +1 -0
  115. package/build/client/_app/immutable/entry/start.BSM2k8tg.js.br +0 -0
  116. package/build/client/_app/immutable/entry/start.BSM2k8tg.js.gz +0 -0
  117. package/build/client/_app/immutable/nodes/0.fnpvsEAN.js +1 -0
  118. package/build/client/_app/immutable/nodes/0.fnpvsEAN.js.br +0 -0
  119. package/build/client/_app/immutable/nodes/0.fnpvsEAN.js.gz +0 -0
  120. package/build/client/_app/immutable/nodes/1.CLtaTeie.js +1 -0
  121. package/build/client/_app/immutable/nodes/1.CLtaTeie.js.br +0 -0
  122. package/build/client/_app/immutable/nodes/1.CLtaTeie.js.gz +0 -0
  123. package/build/client/_app/immutable/nodes/2.BwxFyRtn.js +1 -0
  124. package/build/client/_app/immutable/nodes/2.BwxFyRtn.js.br +0 -0
  125. package/build/client/_app/immutable/nodes/2.BwxFyRtn.js.gz +0 -0
  126. package/build/client/_app/immutable/nodes/3.D2KZBL5g.js +4 -0
  127. package/build/client/_app/immutable/nodes/3.D2KZBL5g.js.br +0 -0
  128. package/build/client/_app/immutable/nodes/3.D2KZBL5g.js.gz +0 -0
  129. package/build/client/_app/immutable/nodes/4.B6LN5K9i.js +1 -0
  130. package/build/client/_app/immutable/nodes/4.B6LN5K9i.js.br +0 -0
  131. package/build/client/_app/immutable/nodes/4.B6LN5K9i.js.gz +0 -0
  132. package/build/client/_app/immutable/nodes/5.CVHYq0o4.js +10 -0
  133. package/build/client/_app/immutable/nodes/5.CVHYq0o4.js.br +0 -0
  134. package/build/client/_app/immutable/nodes/5.CVHYq0o4.js.gz +0 -0
  135. package/build/client/_app/version.json +1 -0
  136. package/build/client/_app/version.json.br +0 -0
  137. package/build/client/_app/version.json.gz +0 -0
  138. package/build/client/robots.txt +3 -0
  139. package/build/client/robots.txt.br +0 -0
  140. package/build/client/robots.txt.gz +0 -0
  141. package/build/env.js +70 -0
  142. package/build/env.js.map +1 -0
  143. package/build/handler.js +17 -0
  144. package/build/handler.js.map +1 -0
  145. package/build/index.js +140 -0
  146. package/build/index.js.map +1 -0
  147. package/build/server/chunks/0-CF_dr3E0.js +9 -0
  148. package/build/server/chunks/0-CF_dr3E0.js.map +1 -0
  149. package/build/server/chunks/1-CVoEVbhQ.js +9 -0
  150. package/build/server/chunks/1-CVoEVbhQ.js.map +1 -0
  151. package/build/server/chunks/2-BzhQC8cX.js +38 -0
  152. package/build/server/chunks/2-BzhQC8cX.js.map +1 -0
  153. package/build/server/chunks/3-CukYFw9L.js +9 -0
  154. package/build/server/chunks/3-CukYFw9L.js.map +1 -0
  155. package/build/server/chunks/4-4e_Gaah7.js +9 -0
  156. package/build/server/chunks/4-4e_Gaah7.js.map +1 -0
  157. package/build/server/chunks/5-B4fCEv4c.js +9 -0
  158. package/build/server/chunks/5-B4fCEv4c.js.map +1 -0
  159. package/build/server/chunks/ChatInput-GWTgCE1t.js +122 -0
  160. package/build/server/chunks/ChatInput-GWTgCE1t.js.map +1 -0
  161. package/build/server/chunks/_layout.svelte-MrMdtdjr.js +232 -0
  162. package/build/server/chunks/_layout.svelte-MrMdtdjr.js.map +1 -0
  163. package/build/server/chunks/_page.svelte-CfQFFres.js +64 -0
  164. package/build/server/chunks/_page.svelte-CfQFFres.js.map +1 -0
  165. package/build/server/chunks/_page.svelte-CgTaVEr0.js +189 -0
  166. package/build/server/chunks/_page.svelte-CgTaVEr0.js.map +1 -0
  167. package/build/server/chunks/_page.svelte-DEDJBB4D.js +602 -0
  168. package/build/server/chunks/_page.svelte-DEDJBB4D.js.map +1 -0
  169. package/build/server/chunks/_page.svelte-OC4xDCWu.js +67 -0
  170. package/build/server/chunks/_page.svelte-OC4xDCWu.js.map +1 -0
  171. package/build/server/chunks/_server.ts-BG3v883h.js +115 -0
  172. package/build/server/chunks/_server.ts-BG3v883h.js.map +1 -0
  173. package/build/server/chunks/_server.ts-C1hU_FnX.js +28 -0
  174. package/build/server/chunks/_server.ts-C1hU_FnX.js.map +1 -0
  175. package/build/server/chunks/_server.ts-CJOrsy4y.js +30 -0
  176. package/build/server/chunks/_server.ts-CJOrsy4y.js.map +1 -0
  177. package/build/server/chunks/_server.ts-Co2FAQm2.js +43 -0
  178. package/build/server/chunks/_server.ts-Co2FAQm2.js.map +1 -0
  179. package/build/server/chunks/_server.ts-D6NGuqud.js +106 -0
  180. package/build/server/chunks/_server.ts-D6NGuqud.js.map +1 -0
  181. package/build/server/chunks/_server.ts-DaHUgm60.js +26 -0
  182. package/build/server/chunks/_server.ts-DaHUgm60.js.map +1 -0
  183. package/build/server/chunks/_server.ts-DiHyx5ij.js +64 -0
  184. package/build/server/chunks/_server.ts-DiHyx5ij.js.map +1 -0
  185. package/build/server/chunks/_server.ts-GB-Qo389.js +73 -0
  186. package/build/server/chunks/_server.ts-GB-Qo389.js.map +1 -0
  187. package/build/server/chunks/_server.ts-K359HUPL.js +32 -0
  188. package/build/server/chunks/_server.ts-K359HUPL.js.map +1 -0
  189. package/build/server/chunks/_server.ts-e4VKCo3M.js +54 -0
  190. package/build/server/chunks/_server.ts-e4VKCo3M.js.map +1 -0
  191. package/build/server/chunks/_server.ts-nr6qwbTw.js +42 -0
  192. package/build/server/chunks/_server.ts-nr6qwbTw.js.map +1 -0
  193. package/build/server/chunks/chat-confirm-BW2aJ2qz.js +5 -0
  194. package/build/server/chunks/chat-confirm-BW2aJ2qz.js.map +1 -0
  195. package/build/server/chunks/chat-steering-DTefLITL.js +5 -0
  196. package/build/server/chunks/chat-steering-DTefLITL.js.map +1 -0
  197. package/build/server/chunks/client-BoLIct8q.js +69 -0
  198. package/build/server/chunks/client-BoLIct8q.js.map +1 -0
  199. package/build/server/chunks/config-d3FC8naq.js +4907 -0
  200. package/build/server/chunks/config-d3FC8naq.js.map +1 -0
  201. package/build/server/chunks/error.svelte-BpxjjtfZ.js +65 -0
  202. package/build/server/chunks/error.svelte-BpxjjtfZ.js.map +1 -0
  203. package/build/server/chunks/gateway-DWcUFfHo.js +478 -0
  204. package/build/server/chunks/gateway-DWcUFfHo.js.map +1 -0
  205. package/build/server/chunks/handler-BAQYBQgy.js +1454 -0
  206. package/build/server/chunks/handler-BAQYBQgy.js.map +1 -0
  207. package/build/server/chunks/hooks.server-C6heBR7o.js +35 -0
  208. package/build/server/chunks/hooks.server-C6heBR7o.js.map +1 -0
  209. package/build/server/chunks/index.js-N7Sh42pC.js +11584 -0
  210. package/build/server/chunks/index.js-N7Sh42pC.js.map +1 -0
  211. package/build/server/chunks/manifest.js-D2rH2GXr.js +143 -0
  212. package/build/server/chunks/manifest.js-D2rH2GXr.js.map +1 -0
  213. package/build/server/chunks/markdown-BYqQ8bKF.js +78593 -0
  214. package/build/server/chunks/markdown-BYqQ8bKF.js.map +1 -0
  215. package/build/server/chunks/prompts-tcGD1LCs.js +37 -0
  216. package/build/server/chunks/prompts-tcGD1LCs.js.map +1 -0
  217. package/build/server/chunks/session-store-B1Aop0Qn.js +50 -0
  218. package/build/server/chunks/session-store-B1Aop0Qn.js.map +1 -0
  219. package/build/server/chunks/stores-D_6JNTkz.js +36 -0
  220. package/build/server/chunks/stores-D_6JNTkz.js.map +1 -0
  221. package/build/shims.js +33 -0
  222. package/build/shims.js.map +1 -0
  223. package/handler.d.ts +8 -0
  224. package/package.json +46 -0
@@ -0,0 +1,1454 @@
1
+ import '../../shims.js';
2
+ import * as fs from 'node:fs';
3
+ import fs__default, { readdirSync, statSync, createReadStream } from 'node:fs';
4
+ import path, { resolve, sep, join, normalize } from 'node:path';
5
+ import process from 'node:process';
6
+ import http from 'node:http';
7
+ import { setImmediate } from 'node:timers';
8
+ import * as qs from 'node:querystring';
9
+ import { Readable } from 'node:stream';
10
+ import { s as splitCookiesString, S as SvelteKitError, a as Server } from './index.js-N7Sh42pC.js';
11
+ import { m as manifest } from './manifest.js-D2rH2GXr.js';
12
+ import { env, dir, env_prefix } from '../../env.js';
13
+ import { format } from 'node:url';
14
+
15
+ function totalist(dir, callback, pre='') {
16
+ dir = resolve('.', dir);
17
+ let arr = readdirSync(dir);
18
+ let i=0, abs, stats;
19
+ for (; i < arr.length; i++) {
20
+ abs = join(dir, arr[i]);
21
+ stats = statSync(abs);
22
+ stats.isDirectory()
23
+ ? totalist(abs, callback, join(pre, arr[i]))
24
+ : callback(join(pre, arr[i]), abs, stats);
25
+ }
26
+ }
27
+
28
+ /**
29
+ * @typedef ParsedURL
30
+ * @type {import('.').ParsedURL}
31
+ */
32
+
33
+ /**
34
+ * @typedef Request
35
+ * @property {string} url
36
+ * @property {ParsedURL} _parsedUrl
37
+ */
38
+
39
+ /**
40
+ * @param {Request} req
41
+ * @returns {ParsedURL|void}
42
+ */
43
+ function parse$1(req) {
44
+ let raw = req.url;
45
+ if (raw == null) return;
46
+
47
+ let prev = req._parsedUrl;
48
+ if (prev && prev.raw === raw) return prev;
49
+
50
+ let pathname=raw, search='', query;
51
+
52
+ if (raw.length > 1) {
53
+ let idx = raw.indexOf('?', 1);
54
+
55
+ if (idx !== -1) {
56
+ search = raw.substring(idx);
57
+ pathname = raw.substring(0, idx);
58
+ if (search.length > 1) {
59
+ query = qs.parse(search.substring(1));
60
+ }
61
+ }
62
+ }
63
+
64
+ return req._parsedUrl = { pathname, search, query, raw };
65
+ }
66
+
67
+ const mimes = {
68
+ "3g2": "video/3gpp2",
69
+ "3gp": "video/3gpp",
70
+ "3gpp": "video/3gpp",
71
+ "3mf": "model/3mf",
72
+ "aac": "audio/aac",
73
+ "ac": "application/pkix-attr-cert",
74
+ "adp": "audio/adpcm",
75
+ "adts": "audio/aac",
76
+ "ai": "application/postscript",
77
+ "aml": "application/automationml-aml+xml",
78
+ "amlx": "application/automationml-amlx+zip",
79
+ "amr": "audio/amr",
80
+ "apng": "image/apng",
81
+ "appcache": "text/cache-manifest",
82
+ "appinstaller": "application/appinstaller",
83
+ "appx": "application/appx",
84
+ "appxbundle": "application/appxbundle",
85
+ "asc": "application/pgp-keys",
86
+ "atom": "application/atom+xml",
87
+ "atomcat": "application/atomcat+xml",
88
+ "atomdeleted": "application/atomdeleted+xml",
89
+ "atomsvc": "application/atomsvc+xml",
90
+ "au": "audio/basic",
91
+ "avci": "image/avci",
92
+ "avcs": "image/avcs",
93
+ "avif": "image/avif",
94
+ "aw": "application/applixware",
95
+ "bdoc": "application/bdoc",
96
+ "bin": "application/octet-stream",
97
+ "bmp": "image/bmp",
98
+ "bpk": "application/octet-stream",
99
+ "btf": "image/prs.btif",
100
+ "btif": "image/prs.btif",
101
+ "buffer": "application/octet-stream",
102
+ "ccxml": "application/ccxml+xml",
103
+ "cdfx": "application/cdfx+xml",
104
+ "cdmia": "application/cdmi-capability",
105
+ "cdmic": "application/cdmi-container",
106
+ "cdmid": "application/cdmi-domain",
107
+ "cdmio": "application/cdmi-object",
108
+ "cdmiq": "application/cdmi-queue",
109
+ "cer": "application/pkix-cert",
110
+ "cgm": "image/cgm",
111
+ "cjs": "application/node",
112
+ "class": "application/java-vm",
113
+ "coffee": "text/coffeescript",
114
+ "conf": "text/plain",
115
+ "cpl": "application/cpl+xml",
116
+ "cpt": "application/mac-compactpro",
117
+ "crl": "application/pkix-crl",
118
+ "css": "text/css",
119
+ "csv": "text/csv",
120
+ "cu": "application/cu-seeme",
121
+ "cwl": "application/cwl",
122
+ "cww": "application/prs.cww",
123
+ "davmount": "application/davmount+xml",
124
+ "dbk": "application/docbook+xml",
125
+ "deb": "application/octet-stream",
126
+ "def": "text/plain",
127
+ "deploy": "application/octet-stream",
128
+ "dib": "image/bmp",
129
+ "disposition-notification": "message/disposition-notification",
130
+ "dist": "application/octet-stream",
131
+ "distz": "application/octet-stream",
132
+ "dll": "application/octet-stream",
133
+ "dmg": "application/octet-stream",
134
+ "dms": "application/octet-stream",
135
+ "doc": "application/msword",
136
+ "dot": "application/msword",
137
+ "dpx": "image/dpx",
138
+ "drle": "image/dicom-rle",
139
+ "dsc": "text/prs.lines.tag",
140
+ "dssc": "application/dssc+der",
141
+ "dtd": "application/xml-dtd",
142
+ "dump": "application/octet-stream",
143
+ "dwd": "application/atsc-dwd+xml",
144
+ "ear": "application/java-archive",
145
+ "ecma": "application/ecmascript",
146
+ "elc": "application/octet-stream",
147
+ "emf": "image/emf",
148
+ "eml": "message/rfc822",
149
+ "emma": "application/emma+xml",
150
+ "emotionml": "application/emotionml+xml",
151
+ "eps": "application/postscript",
152
+ "epub": "application/epub+zip",
153
+ "exe": "application/octet-stream",
154
+ "exi": "application/exi",
155
+ "exp": "application/express",
156
+ "exr": "image/aces",
157
+ "ez": "application/andrew-inset",
158
+ "fdf": "application/fdf",
159
+ "fdt": "application/fdt+xml",
160
+ "fits": "image/fits",
161
+ "g3": "image/g3fax",
162
+ "gbr": "application/rpki-ghostbusters",
163
+ "geojson": "application/geo+json",
164
+ "gif": "image/gif",
165
+ "glb": "model/gltf-binary",
166
+ "gltf": "model/gltf+json",
167
+ "gml": "application/gml+xml",
168
+ "gpx": "application/gpx+xml",
169
+ "gram": "application/srgs",
170
+ "grxml": "application/srgs+xml",
171
+ "gxf": "application/gxf",
172
+ "gz": "application/gzip",
173
+ "h261": "video/h261",
174
+ "h263": "video/h263",
175
+ "h264": "video/h264",
176
+ "heic": "image/heic",
177
+ "heics": "image/heic-sequence",
178
+ "heif": "image/heif",
179
+ "heifs": "image/heif-sequence",
180
+ "hej2": "image/hej2k",
181
+ "held": "application/atsc-held+xml",
182
+ "hjson": "application/hjson",
183
+ "hlp": "application/winhlp",
184
+ "hqx": "application/mac-binhex40",
185
+ "hsj2": "image/hsj2",
186
+ "htm": "text/html",
187
+ "html": "text/html",
188
+ "ics": "text/calendar",
189
+ "ief": "image/ief",
190
+ "ifb": "text/calendar",
191
+ "iges": "model/iges",
192
+ "igs": "model/iges",
193
+ "img": "application/octet-stream",
194
+ "in": "text/plain",
195
+ "ini": "text/plain",
196
+ "ink": "application/inkml+xml",
197
+ "inkml": "application/inkml+xml",
198
+ "ipfix": "application/ipfix",
199
+ "iso": "application/octet-stream",
200
+ "its": "application/its+xml",
201
+ "jade": "text/jade",
202
+ "jar": "application/java-archive",
203
+ "jhc": "image/jphc",
204
+ "jls": "image/jls",
205
+ "jp2": "image/jp2",
206
+ "jpe": "image/jpeg",
207
+ "jpeg": "image/jpeg",
208
+ "jpf": "image/jpx",
209
+ "jpg": "image/jpeg",
210
+ "jpg2": "image/jp2",
211
+ "jpgm": "image/jpm",
212
+ "jpgv": "video/jpeg",
213
+ "jph": "image/jph",
214
+ "jpm": "image/jpm",
215
+ "jpx": "image/jpx",
216
+ "js": "text/javascript",
217
+ "json": "application/json",
218
+ "json5": "application/json5",
219
+ "jsonld": "application/ld+json",
220
+ "jsonml": "application/jsonml+json",
221
+ "jsx": "text/jsx",
222
+ "jt": "model/jt",
223
+ "jxr": "image/jxr",
224
+ "jxra": "image/jxra",
225
+ "jxrs": "image/jxrs",
226
+ "jxs": "image/jxs",
227
+ "jxsc": "image/jxsc",
228
+ "jxsi": "image/jxsi",
229
+ "jxss": "image/jxss",
230
+ "kar": "audio/midi",
231
+ "ktx": "image/ktx",
232
+ "ktx2": "image/ktx2",
233
+ "less": "text/less",
234
+ "lgr": "application/lgr+xml",
235
+ "list": "text/plain",
236
+ "litcoffee": "text/coffeescript",
237
+ "log": "text/plain",
238
+ "lostxml": "application/lost+xml",
239
+ "lrf": "application/octet-stream",
240
+ "m1v": "video/mpeg",
241
+ "m21": "application/mp21",
242
+ "m2a": "audio/mpeg",
243
+ "m2v": "video/mpeg",
244
+ "m3a": "audio/mpeg",
245
+ "m4a": "audio/mp4",
246
+ "m4p": "application/mp4",
247
+ "m4s": "video/iso.segment",
248
+ "ma": "application/mathematica",
249
+ "mads": "application/mads+xml",
250
+ "maei": "application/mmt-aei+xml",
251
+ "man": "text/troff",
252
+ "manifest": "text/cache-manifest",
253
+ "map": "application/json",
254
+ "mar": "application/octet-stream",
255
+ "markdown": "text/markdown",
256
+ "mathml": "application/mathml+xml",
257
+ "mb": "application/mathematica",
258
+ "mbox": "application/mbox",
259
+ "md": "text/markdown",
260
+ "mdx": "text/mdx",
261
+ "me": "text/troff",
262
+ "mesh": "model/mesh",
263
+ "meta4": "application/metalink4+xml",
264
+ "metalink": "application/metalink+xml",
265
+ "mets": "application/mets+xml",
266
+ "mft": "application/rpki-manifest",
267
+ "mid": "audio/midi",
268
+ "midi": "audio/midi",
269
+ "mime": "message/rfc822",
270
+ "mj2": "video/mj2",
271
+ "mjp2": "video/mj2",
272
+ "mjs": "text/javascript",
273
+ "mml": "text/mathml",
274
+ "mods": "application/mods+xml",
275
+ "mov": "video/quicktime",
276
+ "mp2": "audio/mpeg",
277
+ "mp21": "application/mp21",
278
+ "mp2a": "audio/mpeg",
279
+ "mp3": "audio/mpeg",
280
+ "mp4": "video/mp4",
281
+ "mp4a": "audio/mp4",
282
+ "mp4s": "application/mp4",
283
+ "mp4v": "video/mp4",
284
+ "mpd": "application/dash+xml",
285
+ "mpe": "video/mpeg",
286
+ "mpeg": "video/mpeg",
287
+ "mpf": "application/media-policy-dataset+xml",
288
+ "mpg": "video/mpeg",
289
+ "mpg4": "video/mp4",
290
+ "mpga": "audio/mpeg",
291
+ "mpp": "application/dash-patch+xml",
292
+ "mrc": "application/marc",
293
+ "mrcx": "application/marcxml+xml",
294
+ "ms": "text/troff",
295
+ "mscml": "application/mediaservercontrol+xml",
296
+ "msh": "model/mesh",
297
+ "msi": "application/octet-stream",
298
+ "msix": "application/msix",
299
+ "msixbundle": "application/msixbundle",
300
+ "msm": "application/octet-stream",
301
+ "msp": "application/octet-stream",
302
+ "mtl": "model/mtl",
303
+ "musd": "application/mmt-usd+xml",
304
+ "mxf": "application/mxf",
305
+ "mxmf": "audio/mobile-xmf",
306
+ "mxml": "application/xv+xml",
307
+ "n3": "text/n3",
308
+ "nb": "application/mathematica",
309
+ "nq": "application/n-quads",
310
+ "nt": "application/n-triples",
311
+ "obj": "model/obj",
312
+ "oda": "application/oda",
313
+ "oga": "audio/ogg",
314
+ "ogg": "audio/ogg",
315
+ "ogv": "video/ogg",
316
+ "ogx": "application/ogg",
317
+ "omdoc": "application/omdoc+xml",
318
+ "onepkg": "application/onenote",
319
+ "onetmp": "application/onenote",
320
+ "onetoc": "application/onenote",
321
+ "onetoc2": "application/onenote",
322
+ "opf": "application/oebps-package+xml",
323
+ "opus": "audio/ogg",
324
+ "otf": "font/otf",
325
+ "owl": "application/rdf+xml",
326
+ "oxps": "application/oxps",
327
+ "p10": "application/pkcs10",
328
+ "p7c": "application/pkcs7-mime",
329
+ "p7m": "application/pkcs7-mime",
330
+ "p7s": "application/pkcs7-signature",
331
+ "p8": "application/pkcs8",
332
+ "pdf": "application/pdf",
333
+ "pfr": "application/font-tdpfr",
334
+ "pgp": "application/pgp-encrypted",
335
+ "pkg": "application/octet-stream",
336
+ "pki": "application/pkixcmp",
337
+ "pkipath": "application/pkix-pkipath",
338
+ "pls": "application/pls+xml",
339
+ "png": "image/png",
340
+ "prc": "model/prc",
341
+ "prf": "application/pics-rules",
342
+ "provx": "application/provenance+xml",
343
+ "ps": "application/postscript",
344
+ "pskcxml": "application/pskc+xml",
345
+ "pti": "image/prs.pti",
346
+ "qt": "video/quicktime",
347
+ "raml": "application/raml+yaml",
348
+ "rapd": "application/route-apd+xml",
349
+ "rdf": "application/rdf+xml",
350
+ "relo": "application/p2p-overlay+xml",
351
+ "rif": "application/reginfo+xml",
352
+ "rl": "application/resource-lists+xml",
353
+ "rld": "application/resource-lists-diff+xml",
354
+ "rmi": "audio/midi",
355
+ "rnc": "application/relax-ng-compact-syntax",
356
+ "rng": "application/xml",
357
+ "roa": "application/rpki-roa",
358
+ "roff": "text/troff",
359
+ "rq": "application/sparql-query",
360
+ "rs": "application/rls-services+xml",
361
+ "rsat": "application/atsc-rsat+xml",
362
+ "rsd": "application/rsd+xml",
363
+ "rsheet": "application/urc-ressheet+xml",
364
+ "rss": "application/rss+xml",
365
+ "rtf": "text/rtf",
366
+ "rtx": "text/richtext",
367
+ "rusd": "application/route-usd+xml",
368
+ "s3m": "audio/s3m",
369
+ "sbml": "application/sbml+xml",
370
+ "scq": "application/scvp-cv-request",
371
+ "scs": "application/scvp-cv-response",
372
+ "sdp": "application/sdp",
373
+ "senmlx": "application/senml+xml",
374
+ "sensmlx": "application/sensml+xml",
375
+ "ser": "application/java-serialized-object",
376
+ "setpay": "application/set-payment-initiation",
377
+ "setreg": "application/set-registration-initiation",
378
+ "sgi": "image/sgi",
379
+ "sgm": "text/sgml",
380
+ "sgml": "text/sgml",
381
+ "shex": "text/shex",
382
+ "shf": "application/shf+xml",
383
+ "shtml": "text/html",
384
+ "sieve": "application/sieve",
385
+ "sig": "application/pgp-signature",
386
+ "sil": "audio/silk",
387
+ "silo": "model/mesh",
388
+ "siv": "application/sieve",
389
+ "slim": "text/slim",
390
+ "slm": "text/slim",
391
+ "sls": "application/route-s-tsid+xml",
392
+ "smi": "application/smil+xml",
393
+ "smil": "application/smil+xml",
394
+ "snd": "audio/basic",
395
+ "so": "application/octet-stream",
396
+ "spdx": "text/spdx",
397
+ "spp": "application/scvp-vp-response",
398
+ "spq": "application/scvp-vp-request",
399
+ "spx": "audio/ogg",
400
+ "sql": "application/sql",
401
+ "sru": "application/sru+xml",
402
+ "srx": "application/sparql-results+xml",
403
+ "ssdl": "application/ssdl+xml",
404
+ "ssml": "application/ssml+xml",
405
+ "stk": "application/hyperstudio",
406
+ "stl": "model/stl",
407
+ "stpx": "model/step+xml",
408
+ "stpxz": "model/step-xml+zip",
409
+ "stpz": "model/step+zip",
410
+ "styl": "text/stylus",
411
+ "stylus": "text/stylus",
412
+ "svg": "image/svg+xml",
413
+ "svgz": "image/svg+xml",
414
+ "swidtag": "application/swid+xml",
415
+ "t": "text/troff",
416
+ "t38": "image/t38",
417
+ "td": "application/urc-targetdesc+xml",
418
+ "tei": "application/tei+xml",
419
+ "teicorpus": "application/tei+xml",
420
+ "text": "text/plain",
421
+ "tfi": "application/thraud+xml",
422
+ "tfx": "image/tiff-fx",
423
+ "tif": "image/tiff",
424
+ "tiff": "image/tiff",
425
+ "toml": "application/toml",
426
+ "tr": "text/troff",
427
+ "trig": "application/trig",
428
+ "ts": "video/mp2t",
429
+ "tsd": "application/timestamped-data",
430
+ "tsv": "text/tab-separated-values",
431
+ "ttc": "font/collection",
432
+ "ttf": "font/ttf",
433
+ "ttl": "text/turtle",
434
+ "ttml": "application/ttml+xml",
435
+ "txt": "text/plain",
436
+ "u3d": "model/u3d",
437
+ "u8dsn": "message/global-delivery-status",
438
+ "u8hdr": "message/global-headers",
439
+ "u8mdn": "message/global-disposition-notification",
440
+ "u8msg": "message/global",
441
+ "ubj": "application/ubjson",
442
+ "uri": "text/uri-list",
443
+ "uris": "text/uri-list",
444
+ "urls": "text/uri-list",
445
+ "vcard": "text/vcard",
446
+ "vrml": "model/vrml",
447
+ "vtt": "text/vtt",
448
+ "vxml": "application/voicexml+xml",
449
+ "war": "application/java-archive",
450
+ "wasm": "application/wasm",
451
+ "wav": "audio/wav",
452
+ "weba": "audio/webm",
453
+ "webm": "video/webm",
454
+ "webmanifest": "application/manifest+json",
455
+ "webp": "image/webp",
456
+ "wgsl": "text/wgsl",
457
+ "wgt": "application/widget",
458
+ "wif": "application/watcherinfo+xml",
459
+ "wmf": "image/wmf",
460
+ "woff": "font/woff",
461
+ "woff2": "font/woff2",
462
+ "wrl": "model/vrml",
463
+ "wsdl": "application/wsdl+xml",
464
+ "wspolicy": "application/wspolicy+xml",
465
+ "x3d": "model/x3d+xml",
466
+ "x3db": "model/x3d+fastinfoset",
467
+ "x3dbz": "model/x3d+binary",
468
+ "x3dv": "model/x3d-vrml",
469
+ "x3dvz": "model/x3d+vrml",
470
+ "x3dz": "model/x3d+xml",
471
+ "xaml": "application/xaml+xml",
472
+ "xav": "application/xcap-att+xml",
473
+ "xca": "application/xcap-caps+xml",
474
+ "xcs": "application/calendar+xml",
475
+ "xdf": "application/xcap-diff+xml",
476
+ "xdssc": "application/dssc+xml",
477
+ "xel": "application/xcap-el+xml",
478
+ "xenc": "application/xenc+xml",
479
+ "xer": "application/patch-ops-error+xml",
480
+ "xfdf": "application/xfdf",
481
+ "xht": "application/xhtml+xml",
482
+ "xhtml": "application/xhtml+xml",
483
+ "xhvml": "application/xv+xml",
484
+ "xlf": "application/xliff+xml",
485
+ "xm": "audio/xm",
486
+ "xml": "text/xml",
487
+ "xns": "application/xcap-ns+xml",
488
+ "xop": "application/xop+xml",
489
+ "xpl": "application/xproc+xml",
490
+ "xsd": "application/xml",
491
+ "xsf": "application/prs.xsf+xml",
492
+ "xsl": "application/xml",
493
+ "xslt": "application/xml",
494
+ "xspf": "application/xspf+xml",
495
+ "xvm": "application/xv+xml",
496
+ "xvml": "application/xv+xml",
497
+ "yaml": "text/yaml",
498
+ "yang": "application/yang",
499
+ "yin": "application/yin+xml",
500
+ "yml": "text/yaml",
501
+ "zip": "application/zip"
502
+ };
503
+
504
+ function lookup(extn) {
505
+ let tmp = ('' + extn).trim().toLowerCase();
506
+ let idx = tmp.lastIndexOf('.');
507
+ return mimes[!~idx ? tmp : tmp.substring(++idx)];
508
+ }
509
+
510
+ const noop$1 = () => {};
511
+
512
+ function isMatch(uri, arr) {
513
+ for (let i=0; i < arr.length; i++) {
514
+ if (arr[i].test(uri)) return true;
515
+ }
516
+ }
517
+
518
+ function toAssume(uri, extns) {
519
+ let i=0, x, len=uri.length - 1;
520
+ if (uri.charCodeAt(len) === 47) {
521
+ uri = uri.substring(0, len);
522
+ }
523
+
524
+ let arr=[], tmp=`${uri}/index`;
525
+ for (; i < extns.length; i++) {
526
+ x = extns[i] ? `.${extns[i]}` : '';
527
+ if (uri) arr.push(uri + x);
528
+ arr.push(tmp + x);
529
+ }
530
+
531
+ return arr;
532
+ }
533
+
534
+ function viaCache(cache, uri, extns) {
535
+ let i=0, data, arr=toAssume(uri, extns);
536
+ for (; i < arr.length; i++) {
537
+ if (data = cache[arr[i]]) return data;
538
+ }
539
+ }
540
+
541
+ function viaLocal(dir, isEtag, uri, extns) {
542
+ let i=0, arr=toAssume(uri, extns);
543
+ let abs, stats, name, headers;
544
+ for (; i < arr.length; i++) {
545
+ abs = normalize(
546
+ join(dir, name=arr[i])
547
+ );
548
+
549
+ if (abs.startsWith(dir) && fs.existsSync(abs)) {
550
+ stats = fs.statSync(abs);
551
+ if (stats.isDirectory()) continue;
552
+ headers = toHeaders(name, stats, isEtag);
553
+ headers['Cache-Control'] = isEtag ? 'no-cache' : 'no-store';
554
+ return { abs, stats, headers };
555
+ }
556
+ }
557
+ }
558
+
559
+ function is404(req, res) {
560
+ return (res.statusCode=404,res.end());
561
+ }
562
+
563
+ function send(req, res, file, stats, headers) {
564
+ let code=200, tmp, opts={};
565
+ headers = { ...headers };
566
+
567
+ for (let key in headers) {
568
+ tmp = res.getHeader(key);
569
+ if (tmp) headers[key] = tmp;
570
+ }
571
+
572
+ if (tmp = res.getHeader('content-type')) {
573
+ headers['Content-Type'] = tmp;
574
+ }
575
+
576
+ if (req.headers.range) {
577
+ code = 206;
578
+ let [x, y] = req.headers.range.replace('bytes=', '').split('-');
579
+ let end = opts.end = parseInt(y, 10) || stats.size - 1;
580
+ let start = opts.start = parseInt(x, 10) || 0;
581
+
582
+ if (end >= stats.size) {
583
+ end = stats.size - 1;
584
+ }
585
+
586
+ if (start >= stats.size) {
587
+ res.setHeader('Content-Range', `bytes */${stats.size}`);
588
+ res.statusCode = 416;
589
+ return res.end();
590
+ }
591
+
592
+ headers['Content-Range'] = `bytes ${start}-${end}/${stats.size}`;
593
+ headers['Content-Length'] = (end - start + 1);
594
+ headers['Accept-Ranges'] = 'bytes';
595
+ }
596
+
597
+ res.writeHead(code, headers);
598
+ fs.createReadStream(file, opts).pipe(res);
599
+ }
600
+
601
+ const ENCODING = {
602
+ '.br': 'br',
603
+ '.gz': 'gzip',
604
+ };
605
+
606
+ function toHeaders(name, stats, isEtag) {
607
+ let enc = ENCODING[name.slice(-3)];
608
+
609
+ let ctype = lookup(name.slice(0, enc && -3)) || '';
610
+ if (ctype === 'text/html') ctype += ';charset=utf-8';
611
+
612
+ let headers = {
613
+ 'Content-Length': stats.size,
614
+ 'Content-Type': ctype,
615
+ 'Last-Modified': stats.mtime.toUTCString(),
616
+ };
617
+
618
+ if (enc) headers['Content-Encoding'] = enc;
619
+ if (isEtag) headers['ETag'] = `W/"${stats.size}-${stats.mtime.getTime()}"`;
620
+
621
+ return headers;
622
+ }
623
+
624
+ function sirv (dir, opts={}) {
625
+ dir = resolve(dir || '.');
626
+
627
+ let isNotFound = opts.onNoMatch || is404;
628
+ let setHeaders = opts.setHeaders || noop$1;
629
+
630
+ let extensions = opts.extensions || ['html', 'htm'];
631
+ let gzips = opts.gzip && extensions.map(x => `${x}.gz`).concat('gz');
632
+ let brots = opts.brotli && extensions.map(x => `${x}.br`).concat('br');
633
+
634
+ const FILES = {};
635
+
636
+ let fallback = '/';
637
+ let isEtag = !!opts.etag;
638
+ let isSPA = !!opts.single;
639
+ if (typeof opts.single === 'string') {
640
+ let idx = opts.single.lastIndexOf('.');
641
+ fallback += !!~idx ? opts.single.substring(0, idx) : opts.single;
642
+ }
643
+
644
+ let ignores = [];
645
+ if (opts.ignores !== false) {
646
+ ignores.push(/[/]([A-Za-z\s\d~$._-]+\.\w+){1,}$/); // any extn
647
+ if (opts.dotfiles) ignores.push(/\/\.\w/);
648
+ else ignores.push(/\/\.well-known/);
649
+ [].concat(opts.ignores || []).forEach(x => {
650
+ ignores.push(new RegExp(x, 'i'));
651
+ });
652
+ }
653
+
654
+ let cc = opts.maxAge != null && `public,max-age=${opts.maxAge}`;
655
+ if (cc && opts.immutable) cc += ',immutable';
656
+ else if (cc && opts.maxAge === 0) cc += ',must-revalidate';
657
+
658
+ if (!opts.dev) {
659
+ totalist(dir, (name, abs, stats) => {
660
+ if (/\.well-known[\\+\/]/.test(name)) ; // keep
661
+ else if (!opts.dotfiles && /(^\.|[\\+|\/+]\.)/.test(name)) return;
662
+
663
+ let headers = toHeaders(name, stats, isEtag);
664
+ if (cc) headers['Cache-Control'] = cc;
665
+
666
+ FILES['/' + name.normalize().replace(/\\+/g, '/')] = { abs, stats, headers };
667
+ });
668
+ }
669
+
670
+ let lookup = opts.dev ? viaLocal.bind(0, dir + sep, isEtag) : viaCache.bind(0, FILES);
671
+
672
+ return function (req, res, next) {
673
+ let extns = [''];
674
+ let pathname = parse$1(req).pathname;
675
+ let val = req.headers['accept-encoding'] || '';
676
+ if (gzips && val.includes('gzip')) extns.unshift(...gzips);
677
+ if (brots && /(br|brotli)/i.test(val)) extns.unshift(...brots);
678
+ extns.push(...extensions); // [...br, ...gz, orig, ...exts]
679
+
680
+ if (pathname.indexOf('%') !== -1) {
681
+ try { pathname = decodeURI(pathname); }
682
+ catch (err) { /* malform uri */ }
683
+ }
684
+
685
+ let data = lookup(pathname, extns) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns);
686
+ if (!data) return next ? next() : isNotFound(req, res);
687
+
688
+ if (isEtag && req.headers['if-none-match'] === data.headers['ETag']) {
689
+ res.writeHead(304);
690
+ return res.end();
691
+ }
692
+
693
+ if (gzips || brots) {
694
+ res.setHeader('Vary', 'Accept-Encoding');
695
+ }
696
+
697
+ setHeaders(res, pathname, data.stats);
698
+ send(req, res, data.abs, data.stats, data.headers);
699
+ };
700
+ }
701
+
702
+ /**
703
+ * @param {string|RegExp} input The route pattern
704
+ * @param {boolean} [loose] Allow open-ended matching. Ignored with `RegExp` input.
705
+ */
706
+ function parse(input, loose) {
707
+ if (input instanceof RegExp) return { keys:false, pattern:input };
708
+ var c, o, tmp, ext, keys=[], pattern='', arr = input.split('/');
709
+ arr[0] || arr.shift();
710
+
711
+ while (tmp = arr.shift()) {
712
+ c = tmp[0];
713
+ if (c === '*') {
714
+ keys.push(c);
715
+ pattern += tmp[1] === '?' ? '(?:/(.*))?' : '/(.*)';
716
+ } else if (c === ':') {
717
+ o = tmp.indexOf('?', 1);
718
+ ext = tmp.indexOf('.', 1);
719
+ keys.push( tmp.substring(1, !!~o ? o : !!~ext ? ext : tmp.length) );
720
+ pattern += !!~o && !~ext ? '(?:/([^/]+?))?' : '/([^/]+?)';
721
+ if (!!~ext) pattern += (!!~o ? '?' : '') + '\\' + tmp.substring(ext);
722
+ } else {
723
+ pattern += '/' + tmp;
724
+ }
725
+ }
726
+
727
+ return {
728
+ keys: keys,
729
+ pattern: new RegExp('^' + pattern + (loose ? '(?=$|\/)' : '\/?$'), 'i')
730
+ };
731
+ }
732
+
733
+ const MAP = {
734
+ "": 0,
735
+ GET: 1,
736
+ HEAD: 2,
737
+ PATCH: 3,
738
+ OPTIONS: 4,
739
+ CONNECT: 5,
740
+ DELETE: 6,
741
+ TRACE: 7,
742
+ POST: 8,
743
+ PUT: 9,
744
+ };
745
+
746
+ class Trouter {
747
+ constructor() {
748
+ this.routes = [];
749
+
750
+ this.all = this.add.bind(this, '');
751
+ this.get = this.add.bind(this, 'GET');
752
+ this.head = this.add.bind(this, 'HEAD');
753
+ this.patch = this.add.bind(this, 'PATCH');
754
+ this.options = this.add.bind(this, 'OPTIONS');
755
+ this.connect = this.add.bind(this, 'CONNECT');
756
+ this.delete = this.add.bind(this, 'DELETE');
757
+ this.trace = this.add.bind(this, 'TRACE');
758
+ this.post = this.add.bind(this, 'POST');
759
+ this.put = this.add.bind(this, 'PUT');
760
+ }
761
+
762
+ use(route, ...fns) {
763
+ let handlers = [].concat.apply([], fns);
764
+ let { keys, pattern } = parse(route, true);
765
+ this.routes.push({ keys, pattern, method: '', handlers, midx: MAP[''] });
766
+ return this;
767
+ }
768
+
769
+ add(method, route, ...fns) {
770
+ let { keys, pattern } = parse(route);
771
+ let handlers = [].concat.apply([], fns);
772
+ this.routes.push({ keys, pattern, method, handlers, midx: MAP[method] });
773
+ return this;
774
+ }
775
+
776
+ find(method, url) {
777
+ let midx = MAP[method];
778
+ let isHEAD = (midx === 2);
779
+ let i=0, j=0, k, tmp, arr=this.routes;
780
+ let matches=[], params={}, handlers=[];
781
+ for (; i < arr.length; i++) {
782
+ tmp = arr[i];
783
+ if (tmp.midx === midx || tmp.midx === 0 || (isHEAD && tmp.midx===1) ) {
784
+ if (tmp.keys === false) {
785
+ matches = tmp.pattern.exec(url);
786
+ if (matches === null) continue;
787
+ if (matches.groups !== void 0) for (k in matches.groups) params[k]=matches.groups[k];
788
+ tmp.handlers.length > 1 ? (handlers=handlers.concat(tmp.handlers)) : handlers.push(tmp.handlers[0]);
789
+ } else if (tmp.keys.length > 0) {
790
+ matches = tmp.pattern.exec(url);
791
+ if (matches === null) continue;
792
+ for (j=0; j < tmp.keys.length;) params[tmp.keys[j]]=matches[++j];
793
+ tmp.handlers.length > 1 ? (handlers=handlers.concat(tmp.handlers)) : handlers.push(tmp.handlers[0]);
794
+ } else if (tmp.pattern.test(url)) {
795
+ tmp.handlers.length > 1 ? (handlers=handlers.concat(tmp.handlers)) : handlers.push(tmp.handlers[0]);
796
+ }
797
+ } // else not a match
798
+ }
799
+
800
+ return { params, handlers };
801
+ }
802
+ }
803
+
804
+ function onError(err, req, res) {
805
+ let code = typeof err.status === 'number' && err.status;
806
+ code = res.statusCode = (code && code >= 100 ? code : 500);
807
+ if (typeof err === 'string' || Buffer.isBuffer(err)) res.end(err);
808
+ else res.end(err.message || http.STATUS_CODES[code]);
809
+ }
810
+
811
+ const mount = fn => fn instanceof Polka ? fn.attach : fn;
812
+
813
+ class Polka extends Trouter {
814
+ constructor(opts={}) {
815
+ super();
816
+ this.parse = parse$1;
817
+ this.server = opts.server;
818
+ this.handler = this.handler.bind(this);
819
+ this.onError = opts.onError || onError; // catch-all handler
820
+ this.onNoMatch = opts.onNoMatch || this.onError.bind(null, { status: 404 });
821
+ this.attach = (req, res) => setImmediate(this.handler, req, res);
822
+ }
823
+
824
+ use(base, ...fns) {
825
+ if (base === '/') {
826
+ super.use(base, fns.map(mount));
827
+ } else if (typeof base === 'function' || base instanceof Polka) {
828
+ super.use('/', [base, ...fns].map(mount));
829
+ } else {
830
+ super.use(base,
831
+ (req, _, next) => {
832
+ if (typeof base === 'string') {
833
+ let len = base.length;
834
+ base.startsWith('/') || len++;
835
+ req.url = req.url.substring(len) || '/';
836
+ req.path = req.path.substring(len) || '/';
837
+ } else {
838
+ req.url = req.url.replace(base, '') || '/';
839
+ req.path = req.path.replace(base, '') || '/';
840
+ }
841
+ if (req.url.charAt(0) !== '/') {
842
+ req.url = '/' + req.url;
843
+ }
844
+ next();
845
+ },
846
+ fns.map(mount),
847
+ (req, _, next) => {
848
+ req.path = req._parsedUrl.pathname;
849
+ req.url = req.path + req._parsedUrl.search;
850
+ next();
851
+ }
852
+ );
853
+ }
854
+ return this; // chainable
855
+ }
856
+
857
+ listen() {
858
+ (this.server = this.server || http.createServer()).on('request', this.attach);
859
+ this.server.listen.apply(this.server, arguments);
860
+ return this;
861
+ }
862
+
863
+ handler(req, res, next) {
864
+ let info = this.parse(req), path = info.pathname;
865
+ let obj = this.find(req.method, req.path=path);
866
+
867
+ req.url = path + info.search;
868
+ req.originalUrl = req.originalUrl || req.url;
869
+ req.query = info.query || {};
870
+ req.search = info.search;
871
+ req.params = obj.params;
872
+
873
+ if (path.length > 1 && path.indexOf('%', 1) !== -1) {
874
+ for (let k in req.params) {
875
+ try { req.params[k] = decodeURIComponent(req.params[k]); }
876
+ catch (e) { /* malform uri segment */ }
877
+ }
878
+ }
879
+
880
+ let i=0, arr=obj.handlers.concat(this.onNoMatch), len=arr.length;
881
+ let loop = async () => res.finished || (i < len) && arr[i++](req, res, next);
882
+ (next = next || (err => err ? this.onError(err, req, res, next) : loop().catch(next)))(); // init
883
+ }
884
+ }
885
+
886
+ function polka (opts) {
887
+ return new Polka(opts);
888
+ }
889
+
890
+ function noop() {}
891
+
892
+ /**
893
+ * @param {import('http').IncomingMessage} req
894
+ * @param {number} [body_size_limit]
895
+ */
896
+ function get_raw_body(req, body_size_limit) {
897
+ const h = req.headers;
898
+
899
+ if (!h['content-type']) {
900
+ return null;
901
+ }
902
+
903
+ const content_length = Number(h['content-length']);
904
+ const has_content_length = Number.isFinite(content_length);
905
+
906
+ // check if no request body
907
+ if (
908
+ (req.httpVersionMajor === 1 && !has_content_length && h['transfer-encoding'] == null) ||
909
+ content_length === 0
910
+ ) {
911
+ return null;
912
+ }
913
+
914
+ if (req.destroyed) {
915
+ const readable = new ReadableStream();
916
+ void readable.cancel();
917
+ return readable;
918
+ }
919
+
920
+ let size = 0;
921
+ let cancelled = false;
922
+
923
+ return new ReadableStream({
924
+ start(controller) {
925
+ if (body_size_limit !== undefined && has_content_length && content_length > body_size_limit) {
926
+ let message = `Content-length of ${content_length} exceeds limit of ${body_size_limit} bytes.`;
927
+
928
+ if (body_size_limit === 0) {
929
+ // https://github.com/sveltejs/kit/pull/11589
930
+ // TODO this exists to aid migration — remove in a future version
931
+ message += ' To disable body size limits, specify Infinity rather than 0.';
932
+ }
933
+
934
+ const error = new SvelteKitError(413, 'Payload Too Large', message);
935
+
936
+ controller.error(error);
937
+ return;
938
+ }
939
+
940
+ req.on('error', (error) => {
941
+ cancelled = true;
942
+ controller.error(error);
943
+ });
944
+
945
+ req.on('end', () => {
946
+ if (cancelled) return;
947
+ controller.close();
948
+ });
949
+
950
+ req.on('data', (chunk) => {
951
+ if (cancelled) return;
952
+
953
+ size += chunk.length;
954
+
955
+ if (body_size_limit !== undefined && size > body_size_limit) {
956
+ cancelled = true;
957
+
958
+ const message = `request body size exceeded BODY_SIZE_LIMIT of ${body_size_limit}`;
959
+
960
+ const error = new SvelteKitError(413, 'Payload Too Large', message);
961
+ controller.error(error);
962
+
963
+ return;
964
+ }
965
+
966
+ if (has_content_length && size > content_length) {
967
+ cancelled = true;
968
+
969
+ const message = `request body size exceeded content-length of ${content_length}`;
970
+
971
+ const error = new SvelteKitError(413, 'Payload Too Large', message);
972
+ controller.error(error);
973
+
974
+ return;
975
+ }
976
+
977
+ controller.enqueue(chunk);
978
+
979
+ if (controller.desiredSize === null || controller.desiredSize <= 0) {
980
+ req.pause();
981
+ }
982
+ });
983
+ },
984
+
985
+ pull() {
986
+ req.resume();
987
+ },
988
+
989
+ cancel(reason) {
990
+ cancelled = true;
991
+ req.destroy(reason);
992
+ }
993
+ });
994
+ }
995
+
996
+ /**
997
+ * @param {{
998
+ * request: import('http').IncomingMessage;
999
+ * base: string;
1000
+ * bodySizeLimit?: number;
1001
+ * }} options
1002
+ * @returns {Promise<Request>}
1003
+ */
1004
+ // TODO 3.0 make the signature synchronous?
1005
+ // eslint-disable-next-line @typescript-eslint/require-await
1006
+ async function getRequest({ request, base, bodySizeLimit }) {
1007
+ let headers = /** @type {Record<string, string>} */ (request.headers);
1008
+ if (request.httpVersionMajor >= 2) {
1009
+ // the Request constructor rejects headers with ':' in the name
1010
+ headers = Object.assign({}, headers);
1011
+ // https://www.rfc-editor.org/rfc/rfc9113.html#section-8.3.1-2.3.5
1012
+ if (headers[':authority']) {
1013
+ headers.host = headers[':authority'];
1014
+ }
1015
+ delete headers[':authority'];
1016
+ delete headers[':method'];
1017
+ delete headers[':path'];
1018
+ delete headers[':scheme'];
1019
+ }
1020
+
1021
+ // TODO: Whenever Node >=22 is minimum supported version, we can use `request.readableAborted`
1022
+ // @see https://github.com/nodejs/node/blob/5cf3c3e24c7257a0c6192ed8ef71efec8ddac22b/lib/internal/streams/readable.js#L1443-L1453
1023
+ const controller = new AbortController();
1024
+ let errored = false;
1025
+ let end_emitted = false;
1026
+ request.once('error', () => (errored = true));
1027
+ request.once('end', () => (end_emitted = true));
1028
+ request.once('close', () => {
1029
+ if ((errored || request.destroyed) && !end_emitted) {
1030
+ controller.abort();
1031
+ }
1032
+ });
1033
+
1034
+ return new Request(base + request.url, {
1035
+ // @ts-expect-error
1036
+ duplex: 'half',
1037
+ method: request.method,
1038
+ headers: Object.entries(headers),
1039
+ signal: controller.signal,
1040
+ body:
1041
+ request.method === 'GET' || request.method === 'HEAD'
1042
+ ? undefined
1043
+ : get_raw_body(request, bodySizeLimit)
1044
+ });
1045
+ }
1046
+
1047
+ /**
1048
+ * @param {import('http').ServerResponse} res
1049
+ * @param {Response} response
1050
+ * @returns {Promise<void>}
1051
+ */
1052
+ // TODO 3.0 make the signature synchronous?
1053
+ // eslint-disable-next-line @typescript-eslint/require-await
1054
+ async function setResponse(res, response) {
1055
+ for (const [key, value] of response.headers) {
1056
+ try {
1057
+ res.setHeader(
1058
+ key,
1059
+ key === 'set-cookie'
1060
+ ? splitCookiesString(
1061
+ // This is absurd but necessary, TODO: investigate why
1062
+ /** @type {string}*/ (response.headers.get(key))
1063
+ )
1064
+ : value
1065
+ );
1066
+ } catch (error) {
1067
+ res.getHeaderNames().forEach((name) => res.removeHeader(name));
1068
+ res.writeHead(500).end(String(error));
1069
+ return;
1070
+ }
1071
+ }
1072
+
1073
+ res.writeHead(response.status);
1074
+
1075
+ if (!response.body) {
1076
+ res.end();
1077
+ return;
1078
+ }
1079
+
1080
+ if (response.body.locked) {
1081
+ res.end(
1082
+ 'Fatal error: Response body is locked. ' +
1083
+ "This can happen when the response was already read (for example through 'response.json()' or 'response.text()')."
1084
+ );
1085
+ return;
1086
+ }
1087
+
1088
+ const reader = response.body.getReader();
1089
+
1090
+ if (res.destroyed) {
1091
+ void reader.cancel();
1092
+ return;
1093
+ }
1094
+
1095
+ const cancel = (/** @type {Error|undefined} */ error) => {
1096
+ res.off('close', cancel);
1097
+ res.off('error', cancel);
1098
+
1099
+ // If the reader has already been interrupted with an error earlier,
1100
+ // then it will appear here, it is useless, but it needs to be catch.
1101
+ reader.cancel(error).catch(noop);
1102
+ if (error) res.destroy(error);
1103
+ };
1104
+
1105
+ res.on('close', cancel);
1106
+ res.on('error', cancel);
1107
+
1108
+ void next();
1109
+ async function next() {
1110
+ try {
1111
+ for (;;) {
1112
+ const { done, value } = await reader.read();
1113
+
1114
+ if (done) break;
1115
+
1116
+ if (!res.write(value)) {
1117
+ res.once('drain', next);
1118
+ return;
1119
+ }
1120
+ }
1121
+ res.end();
1122
+ } catch (error) {
1123
+ cancel(error instanceof Error ? error : new Error(String(error)));
1124
+ }
1125
+ }
1126
+ }
1127
+
1128
+ /**
1129
+ * Converts a file on disk to a readable stream
1130
+ * @param {string} file
1131
+ * @returns {ReadableStream}
1132
+ * @since 2.4.0
1133
+ */
1134
+ function createReadableStream(file) {
1135
+ return /** @type {ReadableStream} */ (Readable.toWeb(createReadStream(file)));
1136
+ }
1137
+
1138
+ /**
1139
+ * Parses the given value into number of bytes.
1140
+ *
1141
+ * @param {string} value - Size in bytes. Can also be specified with a unit suffix kilobytes (K), megabytes (M), or gigabytes (G).
1142
+ * @returns {number}
1143
+ */
1144
+ function parse_as_bytes(value) {
1145
+ const multiplier =
1146
+ {
1147
+ K: 1024,
1148
+ M: 1024 * 1024,
1149
+ G: 1024 * 1024 * 1024
1150
+ }[value[value.length - 1]?.toUpperCase()] ?? 1;
1151
+ return Number(multiplier != 1 ? value.substring(0, value.length - 1) : value) * multiplier;
1152
+ }
1153
+
1154
+ /**
1155
+ * Parses and validates an origin URL.
1156
+ *
1157
+ * @param {string | undefined} value - Origin URL with http:// or https:// protocol
1158
+ * @returns {string | undefined} The validated origin, or undefined if value is undefined
1159
+ * @throws {Error} If value is provided but invalid
1160
+ */
1161
+ function parse_origin(value) {
1162
+ if (value === undefined) {
1163
+ return undefined;
1164
+ }
1165
+
1166
+ const trimmed = value.trim();
1167
+
1168
+ let url;
1169
+ try {
1170
+ url = new URL(trimmed);
1171
+ } catch (error) {
1172
+ throw new Error(
1173
+ `Invalid ORIGIN: '${trimmed}'. ` +
1174
+ `ORIGIN must be a valid URL with http:// or https:// protocol. ` +
1175
+ `For example: 'http://localhost:3000' or 'https://my.site'`,
1176
+ { cause: error }
1177
+ );
1178
+ }
1179
+
1180
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
1181
+ throw new Error(
1182
+ `Invalid ORIGIN: '${trimmed}'. ` +
1183
+ `Only http:// and https:// protocols are supported. ` +
1184
+ `Received protocol: ${url.protocol}`
1185
+ );
1186
+ }
1187
+
1188
+ return url.origin;
1189
+ }
1190
+
1191
+ /**
1192
+ * Formats the address the server is listening on.
1193
+ *
1194
+ * @param {string | false} path
1195
+ * @param {string} host
1196
+ * @param {string | false} port
1197
+ * @param {import('node:net').AddressInfo | string | null} address
1198
+ * @returns {string}
1199
+ */
1200
+ function format_listening_address(path, host, port, address) {
1201
+ if (path) {
1202
+ return path;
1203
+ }
1204
+
1205
+ if (address && typeof address === 'object') {
1206
+ return format({
1207
+ protocol: 'http:',
1208
+ hostname: address.address,
1209
+ port: address.port
1210
+ });
1211
+ }
1212
+
1213
+ return format({
1214
+ protocol: 'http:',
1215
+ hostname: host,
1216
+ port: String(port)
1217
+ });
1218
+ }
1219
+
1220
+ const prerendered = new Set([]);
1221
+
1222
+ const server = new Server(manifest);
1223
+
1224
+ // parse_origin validates ORIGIN and throws descriptive errors for invalid values
1225
+ const origin = parse_origin(env('ORIGIN', undefined));
1226
+
1227
+ const xff_depth = parseInt(env('XFF_DEPTH', '1'));
1228
+ const address_header = env('ADDRESS_HEADER', '').toLowerCase();
1229
+ const protocol_header = env('PROTOCOL_HEADER', '').toLowerCase();
1230
+ const host_header = env('HOST_HEADER', '').toLowerCase();
1231
+ const port_header = env('PORT_HEADER', '').toLowerCase();
1232
+
1233
+ const body_size_limit = parse_as_bytes(env('BODY_SIZE_LIMIT', '512K'));
1234
+
1235
+ if (isNaN(body_size_limit)) {
1236
+ throw new Error(
1237
+ `Invalid BODY_SIZE_LIMIT: '${env('BODY_SIZE_LIMIT')}'. Please provide a numeric value.`
1238
+ );
1239
+ }
1240
+
1241
+ const asset_dir = `${dir}/client${""}`;
1242
+
1243
+ await server.init({
1244
+ env: /** @type {Record<string, string>} */ (process.env),
1245
+ read: (file) => createReadableStream(`${asset_dir}/${file}`)
1246
+ });
1247
+
1248
+ /**
1249
+ * @param {string} path
1250
+ * @param {boolean} client
1251
+ */
1252
+ function serve(path, client = false) {
1253
+ return fs__default.existsSync(path)
1254
+ ? sirv(path, {
1255
+ etag: true,
1256
+ gzip: true,
1257
+ brotli: true,
1258
+ setHeaders: client
1259
+ ? (res, pathname) => {
1260
+ // only apply to build directory, not e.g. version.json
1261
+ if (
1262
+ pathname.startsWith(`/${manifest.appPath}/immutable/`) &&
1263
+ res.statusCode === 200
1264
+ ) {
1265
+ res.setHeader('cache-control', 'public,max-age=31536000,immutable');
1266
+ }
1267
+ }
1268
+ : undefined
1269
+ })
1270
+ : undefined;
1271
+ }
1272
+
1273
+ // required because the static file server ignores trailing slashes
1274
+ /** @returns {import('polka').Middleware} */
1275
+ function serve_prerendered() {
1276
+ const handler = serve(path.join(dir, 'prerendered'));
1277
+
1278
+ return (req, res, next) => {
1279
+ let { pathname, search, query } = parse$1(req);
1280
+
1281
+ try {
1282
+ pathname = decodeURIComponent(pathname);
1283
+ } catch {
1284
+ // ignore invalid URI
1285
+ }
1286
+
1287
+ if (prerendered.has(pathname)) {
1288
+ return handler?.(req, res, next);
1289
+ }
1290
+
1291
+ // remove or add trailing slash as appropriate
1292
+ let location = pathname.at(-1) === '/' ? pathname.slice(0, -1) : pathname + '/';
1293
+ if (prerendered.has(location)) {
1294
+ if (query) location += search;
1295
+ res.writeHead(308, { location }).end();
1296
+ } else {
1297
+ void next();
1298
+ }
1299
+ };
1300
+ }
1301
+
1302
+ /** @type {import('polka').Middleware} */
1303
+ const ssr = async (req, res) => {
1304
+ /** @type {Request} */
1305
+ let request;
1306
+
1307
+ try {
1308
+ request = await getRequest({
1309
+ base: origin || get_origin(req.headers),
1310
+ request: req,
1311
+ bodySizeLimit: body_size_limit
1312
+ });
1313
+ } catch {
1314
+ res.statusCode = 400;
1315
+ res.end('Bad Request');
1316
+ return;
1317
+ }
1318
+
1319
+ const response = await server.respond(request, {
1320
+ platform: { req },
1321
+ getClientAddress: () => {
1322
+ if (address_header) {
1323
+ if (!(address_header in req.headers)) {
1324
+ throw new Error(
1325
+ `Address header was specified with ${
1326
+ env_prefix + 'ADDRESS_HEADER'
1327
+ }=${address_header} but is absent from request`
1328
+ );
1329
+ }
1330
+
1331
+ const value = /** @type {string} */ (req.headers[address_header]) || '';
1332
+
1333
+ if (address_header === 'x-forwarded-for') {
1334
+ const addresses = value.split(',');
1335
+
1336
+ if (xff_depth < 1) {
1337
+ throw new Error(`${env_prefix + 'XFF_DEPTH'} must be a positive integer`);
1338
+ }
1339
+
1340
+ if (xff_depth > addresses.length) {
1341
+ throw new Error(
1342
+ `${env_prefix + 'XFF_DEPTH'} is ${xff_depth}, but only found ${
1343
+ addresses.length
1344
+ } addresses`
1345
+ );
1346
+ }
1347
+ return addresses[addresses.length - xff_depth].trim();
1348
+ }
1349
+
1350
+ return value;
1351
+ }
1352
+
1353
+ return (
1354
+ req.connection?.remoteAddress ||
1355
+ // @ts-expect-error
1356
+ req.connection?.socket?.remoteAddress ||
1357
+ req.socket?.remoteAddress ||
1358
+ // @ts-expect-error
1359
+ req.info?.remoteAddress
1360
+ );
1361
+ }
1362
+ });
1363
+
1364
+ // Reverse proxies such as nginx buffer responses by default (ignoring
1365
+ // `cache-control`), which breaks streaming responses like server-sent events.
1366
+ // `X-Accel-Buffering: no` opts out of that buffering and is a no-op on proxies
1367
+ // that don't recognise it. See https://github.com/sveltejs/kit/issues/15790
1368
+ if (response.headers.get('content-type') === 'text/event-stream') {
1369
+ response.headers.set('x-accel-buffering', 'no');
1370
+ }
1371
+
1372
+ await setResponse(res, response);
1373
+ };
1374
+
1375
+ /** @param {import('polka').Middleware[]} handlers */
1376
+ function sequence(handlers) {
1377
+ /** @type {import('polka').Middleware} */
1378
+ return (req, res, next) => {
1379
+ /**
1380
+ * @param {number} i
1381
+ * @returns {ReturnType<import('polka').Middleware>}
1382
+ */
1383
+ function handle(i) {
1384
+ if (i < handlers.length) {
1385
+ return handlers[i](req, res, () => handle(i + 1));
1386
+ } else {
1387
+ return next();
1388
+ }
1389
+ }
1390
+
1391
+ return handle(0);
1392
+ };
1393
+ }
1394
+
1395
+ /**
1396
+ * @param {string} name
1397
+ * @param {string | string[] | undefined} value
1398
+ * @returns {string | undefined}
1399
+ */
1400
+ function normalise_header(name, value) {
1401
+ if (!name) return undefined;
1402
+ if (Array.isArray(value)) {
1403
+ if (value.length === 0) return undefined;
1404
+ if (value.length === 1) return value[0];
1405
+ throw new Error(
1406
+ `Multiple values provided for ${name} header where only one expected: ${value}`
1407
+ );
1408
+ }
1409
+ return value;
1410
+ }
1411
+
1412
+ /**
1413
+ * @param {import('http').IncomingHttpHeaders} headers
1414
+ * @returns {string}
1415
+ */
1416
+ function get_origin(headers) {
1417
+ const protocol = decodeURIComponent(
1418
+ normalise_header(protocol_header, headers[protocol_header]) || 'https'
1419
+ );
1420
+
1421
+ // this helps us avoid host injections through the protocol header
1422
+ if (protocol.includes(':')) {
1423
+ throw new Error(
1424
+ `The ${protocol_header} header specified ${protocol} which is an invalid because it includes \`:\`. It should only contain the protocol scheme (e.g. \`https\`)`
1425
+ );
1426
+ }
1427
+
1428
+ const host =
1429
+ normalise_header(host_header, headers[host_header]) ||
1430
+ normalise_header('host', headers['host']);
1431
+ if (!host) {
1432
+ const header_names = host_header ? `${host_header} or host headers` : 'host header';
1433
+ throw new Error(
1434
+ `Could not determine host. The request must have a value provided by the ${header_names}`
1435
+ );
1436
+ }
1437
+
1438
+ const port = normalise_header(port_header, headers[port_header]);
1439
+ if (port && isNaN(+port)) {
1440
+ throw new Error(
1441
+ `The ${port_header} header specified ${port} which is an invalid port because it is not a number. The value should only contain the port number (e.g. 443)`
1442
+ );
1443
+ }
1444
+
1445
+ return port ? `${protocol}://${host}:${port}` : `${protocol}://${host}`;
1446
+ }
1447
+
1448
+ const handler = sequence(
1449
+ /** @type {(import('sirv').RequestHandler | import('polka').Middleware)[]} */
1450
+ ([serve(path.join(dir, 'client'), true), serve_prerendered(), ssr].filter(Boolean))
1451
+ );
1452
+
1453
+ export { format_listening_address as f, handler as h, polka as p };
1454
+ //# sourceMappingURL=handler-BAQYBQgy.js.map