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