@sveltejs/kit 1.0.0-next.230 → 1.0.0-next.234

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.
@@ -1,13 +1,14 @@
1
- import * as fs from 'fs';
2
- import fs__default, { readdirSync, statSync } from 'fs';
1
+ import fs__default from 'fs';
3
2
  import http from 'http';
4
3
  import https from 'https';
5
- import { resolve, join, normalize } from 'path';
6
- import * as qs from 'querystring';
4
+ import { resolve, join } from 'path';
5
+ import { s as sirv, t as to_headers } from './http.js';
7
6
  import { pathToFileURL } from 'url';
8
7
  import { getRawBody } from '../node.js';
9
8
  import { __fetch_polyfill } from '../install-fetch.js';
10
- import { S as SVELTE_KIT, b as SVELTE_KIT_ASSETS } from '../cli.js';
9
+ import { a as SVELTE_KIT, S as SVELTE_KIT_ASSETS } from '../cli.js';
10
+ import 'querystring';
11
+ import 'stream';
11
12
  import 'node:http';
12
13
  import 'node:https';
13
14
  import 'node:zlib';
@@ -19,658 +20,6 @@ import 'sade';
19
20
  import 'child_process';
20
21
  import 'os';
21
22
 
22
- function totalist(dir, callback, pre='') {
23
- dir = resolve('.', dir);
24
- let arr = readdirSync(dir);
25
- let i=0, abs, stats;
26
- for (; i < arr.length; i++) {
27
- abs = join(dir, arr[i]);
28
- stats = statSync(abs);
29
- stats.isDirectory()
30
- ? totalist(abs, callback, join(pre, arr[i]))
31
- : callback(join(pre, arr[i]), abs, stats);
32
- }
33
- }
34
-
35
- /**
36
- * @typedef ParsedURL
37
- * @type {import('.').ParsedURL}
38
- */
39
-
40
- /**
41
- * @typedef Request
42
- * @property {string} url
43
- * @property {ParsedURL} _parsedUrl
44
- */
45
-
46
- /**
47
- * @param {Request} req
48
- * @returns {ParsedURL|void}
49
- */
50
- function parse(req) {
51
- let raw = req.url;
52
- if (raw == null) return;
53
-
54
- let prev = req._parsedUrl;
55
- if (prev && prev.raw === raw) return prev;
56
-
57
- let pathname=raw, search='', query;
58
-
59
- if (raw.length > 1) {
60
- let idx = raw.indexOf('?', 1);
61
-
62
- if (idx !== -1) {
63
- search = raw.substring(idx);
64
- pathname = raw.substring(0, idx);
65
- if (search.length > 1) {
66
- query = qs.parse(search.substring(1));
67
- }
68
- }
69
- }
70
-
71
- return req._parsedUrl = { pathname, search, query, raw };
72
- }
73
-
74
- const mimes = {
75
- "ez": "application/andrew-inset",
76
- "aw": "application/applixware",
77
- "atom": "application/atom+xml",
78
- "atomcat": "application/atomcat+xml",
79
- "atomdeleted": "application/atomdeleted+xml",
80
- "atomsvc": "application/atomsvc+xml",
81
- "dwd": "application/atsc-dwd+xml",
82
- "held": "application/atsc-held+xml",
83
- "rsat": "application/atsc-rsat+xml",
84
- "bdoc": "application/bdoc",
85
- "xcs": "application/calendar+xml",
86
- "ccxml": "application/ccxml+xml",
87
- "cdfx": "application/cdfx+xml",
88
- "cdmia": "application/cdmi-capability",
89
- "cdmic": "application/cdmi-container",
90
- "cdmid": "application/cdmi-domain",
91
- "cdmio": "application/cdmi-object",
92
- "cdmiq": "application/cdmi-queue",
93
- "cu": "application/cu-seeme",
94
- "mpd": "application/dash+xml",
95
- "davmount": "application/davmount+xml",
96
- "dbk": "application/docbook+xml",
97
- "dssc": "application/dssc+der",
98
- "xdssc": "application/dssc+xml",
99
- "es": "application/ecmascript",
100
- "ecma": "application/ecmascript",
101
- "emma": "application/emma+xml",
102
- "emotionml": "application/emotionml+xml",
103
- "epub": "application/epub+zip",
104
- "exi": "application/exi",
105
- "fdt": "application/fdt+xml",
106
- "pfr": "application/font-tdpfr",
107
- "geojson": "application/geo+json",
108
- "gml": "application/gml+xml",
109
- "gpx": "application/gpx+xml",
110
- "gxf": "application/gxf",
111
- "gz": "application/gzip",
112
- "hjson": "application/hjson",
113
- "stk": "application/hyperstudio",
114
- "ink": "application/inkml+xml",
115
- "inkml": "application/inkml+xml",
116
- "ipfix": "application/ipfix",
117
- "its": "application/its+xml",
118
- "jar": "application/java-archive",
119
- "war": "application/java-archive",
120
- "ear": "application/java-archive",
121
- "ser": "application/java-serialized-object",
122
- "class": "application/java-vm",
123
- "js": "application/javascript",
124
- "mjs": "application/javascript",
125
- "json": "application/json",
126
- "map": "application/json",
127
- "json5": "application/json5",
128
- "jsonml": "application/jsonml+json",
129
- "jsonld": "application/ld+json",
130
- "lgr": "application/lgr+xml",
131
- "lostxml": "application/lost+xml",
132
- "hqx": "application/mac-binhex40",
133
- "cpt": "application/mac-compactpro",
134
- "mads": "application/mads+xml",
135
- "webmanifest": "application/manifest+json",
136
- "mrc": "application/marc",
137
- "mrcx": "application/marcxml+xml",
138
- "ma": "application/mathematica",
139
- "nb": "application/mathematica",
140
- "mb": "application/mathematica",
141
- "mathml": "application/mathml+xml",
142
- "mbox": "application/mbox",
143
- "mscml": "application/mediaservercontrol+xml",
144
- "metalink": "application/metalink+xml",
145
- "meta4": "application/metalink4+xml",
146
- "mets": "application/mets+xml",
147
- "maei": "application/mmt-aei+xml",
148
- "musd": "application/mmt-usd+xml",
149
- "mods": "application/mods+xml",
150
- "m21": "application/mp21",
151
- "mp21": "application/mp21",
152
- "mp4s": "application/mp4",
153
- "m4p": "application/mp4",
154
- "doc": "application/msword",
155
- "dot": "application/msword",
156
- "mxf": "application/mxf",
157
- "nq": "application/n-quads",
158
- "nt": "application/n-triples",
159
- "cjs": "application/node",
160
- "bin": "application/octet-stream",
161
- "dms": "application/octet-stream",
162
- "lrf": "application/octet-stream",
163
- "mar": "application/octet-stream",
164
- "so": "application/octet-stream",
165
- "dist": "application/octet-stream",
166
- "distz": "application/octet-stream",
167
- "pkg": "application/octet-stream",
168
- "bpk": "application/octet-stream",
169
- "dump": "application/octet-stream",
170
- "elc": "application/octet-stream",
171
- "deploy": "application/octet-stream",
172
- "exe": "application/octet-stream",
173
- "dll": "application/octet-stream",
174
- "deb": "application/octet-stream",
175
- "dmg": "application/octet-stream",
176
- "iso": "application/octet-stream",
177
- "img": "application/octet-stream",
178
- "msi": "application/octet-stream",
179
- "msp": "application/octet-stream",
180
- "msm": "application/octet-stream",
181
- "buffer": "application/octet-stream",
182
- "oda": "application/oda",
183
- "opf": "application/oebps-package+xml",
184
- "ogx": "application/ogg",
185
- "omdoc": "application/omdoc+xml",
186
- "onetoc": "application/onenote",
187
- "onetoc2": "application/onenote",
188
- "onetmp": "application/onenote",
189
- "onepkg": "application/onenote",
190
- "oxps": "application/oxps",
191
- "relo": "application/p2p-overlay+xml",
192
- "xer": "application/patch-ops-error+xml",
193
- "pdf": "application/pdf",
194
- "pgp": "application/pgp-encrypted",
195
- "asc": "application/pgp-signature",
196
- "sig": "application/pgp-signature",
197
- "prf": "application/pics-rules",
198
- "p10": "application/pkcs10",
199
- "p7m": "application/pkcs7-mime",
200
- "p7c": "application/pkcs7-mime",
201
- "p7s": "application/pkcs7-signature",
202
- "p8": "application/pkcs8",
203
- "ac": "application/pkix-attr-cert",
204
- "cer": "application/pkix-cert",
205
- "crl": "application/pkix-crl",
206
- "pkipath": "application/pkix-pkipath",
207
- "pki": "application/pkixcmp",
208
- "pls": "application/pls+xml",
209
- "ai": "application/postscript",
210
- "eps": "application/postscript",
211
- "ps": "application/postscript",
212
- "provx": "application/provenance+xml",
213
- "cww": "application/prs.cww",
214
- "pskcxml": "application/pskc+xml",
215
- "raml": "application/raml+yaml",
216
- "rdf": "application/rdf+xml",
217
- "owl": "application/rdf+xml",
218
- "rif": "application/reginfo+xml",
219
- "rnc": "application/relax-ng-compact-syntax",
220
- "rl": "application/resource-lists+xml",
221
- "rld": "application/resource-lists-diff+xml",
222
- "rs": "application/rls-services+xml",
223
- "rapd": "application/route-apd+xml",
224
- "sls": "application/route-s-tsid+xml",
225
- "rusd": "application/route-usd+xml",
226
- "gbr": "application/rpki-ghostbusters",
227
- "mft": "application/rpki-manifest",
228
- "roa": "application/rpki-roa",
229
- "rsd": "application/rsd+xml",
230
- "rss": "application/rss+xml",
231
- "rtf": "application/rtf",
232
- "sbml": "application/sbml+xml",
233
- "scq": "application/scvp-cv-request",
234
- "scs": "application/scvp-cv-response",
235
- "spq": "application/scvp-vp-request",
236
- "spp": "application/scvp-vp-response",
237
- "sdp": "application/sdp",
238
- "senmlx": "application/senml+xml",
239
- "sensmlx": "application/sensml+xml",
240
- "setpay": "application/set-payment-initiation",
241
- "setreg": "application/set-registration-initiation",
242
- "shf": "application/shf+xml",
243
- "siv": "application/sieve",
244
- "sieve": "application/sieve",
245
- "smi": "application/smil+xml",
246
- "smil": "application/smil+xml",
247
- "rq": "application/sparql-query",
248
- "srx": "application/sparql-results+xml",
249
- "gram": "application/srgs",
250
- "grxml": "application/srgs+xml",
251
- "sru": "application/sru+xml",
252
- "ssdl": "application/ssdl+xml",
253
- "ssml": "application/ssml+xml",
254
- "swidtag": "application/swid+xml",
255
- "tei": "application/tei+xml",
256
- "teicorpus": "application/tei+xml",
257
- "tfi": "application/thraud+xml",
258
- "tsd": "application/timestamped-data",
259
- "toml": "application/toml",
260
- "trig": "application/trig",
261
- "ttml": "application/ttml+xml",
262
- "ubj": "application/ubjson",
263
- "rsheet": "application/urc-ressheet+xml",
264
- "td": "application/urc-targetdesc+xml",
265
- "vxml": "application/voicexml+xml",
266
- "wasm": "application/wasm",
267
- "wgt": "application/widget",
268
- "hlp": "application/winhlp",
269
- "wsdl": "application/wsdl+xml",
270
- "wspolicy": "application/wspolicy+xml",
271
- "xaml": "application/xaml+xml",
272
- "xav": "application/xcap-att+xml",
273
- "xca": "application/xcap-caps+xml",
274
- "xdf": "application/xcap-diff+xml",
275
- "xel": "application/xcap-el+xml",
276
- "xns": "application/xcap-ns+xml",
277
- "xenc": "application/xenc+xml",
278
- "xhtml": "application/xhtml+xml",
279
- "xht": "application/xhtml+xml",
280
- "xlf": "application/xliff+xml",
281
- "xml": "application/xml",
282
- "xsl": "application/xml",
283
- "xsd": "application/xml",
284
- "rng": "application/xml",
285
- "dtd": "application/xml-dtd",
286
- "xop": "application/xop+xml",
287
- "xpl": "application/xproc+xml",
288
- "xslt": "application/xml",
289
- "xspf": "application/xspf+xml",
290
- "mxml": "application/xv+xml",
291
- "xhvml": "application/xv+xml",
292
- "xvml": "application/xv+xml",
293
- "xvm": "application/xv+xml",
294
- "yang": "application/yang",
295
- "yin": "application/yin+xml",
296
- "zip": "application/zip",
297
- "3gpp": "video/3gpp",
298
- "adp": "audio/adpcm",
299
- "amr": "audio/amr",
300
- "au": "audio/basic",
301
- "snd": "audio/basic",
302
- "mid": "audio/midi",
303
- "midi": "audio/midi",
304
- "kar": "audio/midi",
305
- "rmi": "audio/midi",
306
- "mxmf": "audio/mobile-xmf",
307
- "mp3": "audio/mpeg",
308
- "m4a": "audio/mp4",
309
- "mp4a": "audio/mp4",
310
- "mpga": "audio/mpeg",
311
- "mp2": "audio/mpeg",
312
- "mp2a": "audio/mpeg",
313
- "m2a": "audio/mpeg",
314
- "m3a": "audio/mpeg",
315
- "oga": "audio/ogg",
316
- "ogg": "audio/ogg",
317
- "spx": "audio/ogg",
318
- "opus": "audio/ogg",
319
- "s3m": "audio/s3m",
320
- "sil": "audio/silk",
321
- "wav": "audio/wav",
322
- "weba": "audio/webm",
323
- "xm": "audio/xm",
324
- "ttc": "font/collection",
325
- "otf": "font/otf",
326
- "ttf": "font/ttf",
327
- "woff": "font/woff",
328
- "woff2": "font/woff2",
329
- "exr": "image/aces",
330
- "apng": "image/apng",
331
- "avif": "image/avif",
332
- "bmp": "image/bmp",
333
- "cgm": "image/cgm",
334
- "drle": "image/dicom-rle",
335
- "emf": "image/emf",
336
- "fits": "image/fits",
337
- "g3": "image/g3fax",
338
- "gif": "image/gif",
339
- "heic": "image/heic",
340
- "heics": "image/heic-sequence",
341
- "heif": "image/heif",
342
- "heifs": "image/heif-sequence",
343
- "hej2": "image/hej2k",
344
- "hsj2": "image/hsj2",
345
- "ief": "image/ief",
346
- "jls": "image/jls",
347
- "jp2": "image/jp2",
348
- "jpg2": "image/jp2",
349
- "jpeg": "image/jpeg",
350
- "jpg": "image/jpeg",
351
- "jpe": "image/jpeg",
352
- "jph": "image/jph",
353
- "jhc": "image/jphc",
354
- "jpm": "image/jpm",
355
- "jpx": "image/jpx",
356
- "jpf": "image/jpx",
357
- "jxr": "image/jxr",
358
- "jxra": "image/jxra",
359
- "jxrs": "image/jxrs",
360
- "jxs": "image/jxs",
361
- "jxsc": "image/jxsc",
362
- "jxsi": "image/jxsi",
363
- "jxss": "image/jxss",
364
- "ktx": "image/ktx",
365
- "ktx2": "image/ktx2",
366
- "png": "image/png",
367
- "btif": "image/prs.btif",
368
- "pti": "image/prs.pti",
369
- "sgi": "image/sgi",
370
- "svg": "image/svg+xml",
371
- "svgz": "image/svg+xml",
372
- "t38": "image/t38",
373
- "tif": "image/tiff",
374
- "tiff": "image/tiff",
375
- "tfx": "image/tiff-fx",
376
- "webp": "image/webp",
377
- "wmf": "image/wmf",
378
- "disposition-notification": "message/disposition-notification",
379
- "u8msg": "message/global",
380
- "u8dsn": "message/global-delivery-status",
381
- "u8mdn": "message/global-disposition-notification",
382
- "u8hdr": "message/global-headers",
383
- "eml": "message/rfc822",
384
- "mime": "message/rfc822",
385
- "3mf": "model/3mf",
386
- "gltf": "model/gltf+json",
387
- "glb": "model/gltf-binary",
388
- "igs": "model/iges",
389
- "iges": "model/iges",
390
- "msh": "model/mesh",
391
- "mesh": "model/mesh",
392
- "silo": "model/mesh",
393
- "mtl": "model/mtl",
394
- "obj": "model/obj",
395
- "stpz": "model/step+zip",
396
- "stpxz": "model/step-xml+zip",
397
- "stl": "model/stl",
398
- "wrl": "model/vrml",
399
- "vrml": "model/vrml",
400
- "x3db": "model/x3d+fastinfoset",
401
- "x3dbz": "model/x3d+binary",
402
- "x3dv": "model/x3d-vrml",
403
- "x3dvz": "model/x3d+vrml",
404
- "x3d": "model/x3d+xml",
405
- "x3dz": "model/x3d+xml",
406
- "appcache": "text/cache-manifest",
407
- "manifest": "text/cache-manifest",
408
- "ics": "text/calendar",
409
- "ifb": "text/calendar",
410
- "coffee": "text/coffeescript",
411
- "litcoffee": "text/coffeescript",
412
- "css": "text/css",
413
- "csv": "text/csv",
414
- "html": "text/html",
415
- "htm": "text/html",
416
- "shtml": "text/html",
417
- "jade": "text/jade",
418
- "jsx": "text/jsx",
419
- "less": "text/less",
420
- "markdown": "text/markdown",
421
- "md": "text/markdown",
422
- "mml": "text/mathml",
423
- "mdx": "text/mdx",
424
- "n3": "text/n3",
425
- "txt": "text/plain",
426
- "text": "text/plain",
427
- "conf": "text/plain",
428
- "def": "text/plain",
429
- "list": "text/plain",
430
- "log": "text/plain",
431
- "in": "text/plain",
432
- "ini": "text/plain",
433
- "dsc": "text/prs.lines.tag",
434
- "rtx": "text/richtext",
435
- "sgml": "text/sgml",
436
- "sgm": "text/sgml",
437
- "shex": "text/shex",
438
- "slim": "text/slim",
439
- "slm": "text/slim",
440
- "spdx": "text/spdx",
441
- "stylus": "text/stylus",
442
- "styl": "text/stylus",
443
- "tsv": "text/tab-separated-values",
444
- "t": "text/troff",
445
- "tr": "text/troff",
446
- "roff": "text/troff",
447
- "man": "text/troff",
448
- "me": "text/troff",
449
- "ms": "text/troff",
450
- "ttl": "text/turtle",
451
- "uri": "text/uri-list",
452
- "uris": "text/uri-list",
453
- "urls": "text/uri-list",
454
- "vcard": "text/vcard",
455
- "vtt": "text/vtt",
456
- "yaml": "text/yaml",
457
- "yml": "text/yaml",
458
- "3gp": "video/3gpp",
459
- "3g2": "video/3gpp2",
460
- "h261": "video/h261",
461
- "h263": "video/h263",
462
- "h264": "video/h264",
463
- "m4s": "video/iso.segment",
464
- "jpgv": "video/jpeg",
465
- "jpgm": "image/jpm",
466
- "mj2": "video/mj2",
467
- "mjp2": "video/mj2",
468
- "ts": "video/mp2t",
469
- "mp4": "video/mp4",
470
- "mp4v": "video/mp4",
471
- "mpg4": "video/mp4",
472
- "mpeg": "video/mpeg",
473
- "mpg": "video/mpeg",
474
- "mpe": "video/mpeg",
475
- "m1v": "video/mpeg",
476
- "m2v": "video/mpeg",
477
- "ogv": "video/ogg",
478
- "qt": "video/quicktime",
479
- "mov": "video/quicktime",
480
- "webm": "video/webm"
481
- };
482
-
483
- function lookup(extn) {
484
- let tmp = ('' + extn).trim().toLowerCase();
485
- let idx = tmp.lastIndexOf('.');
486
- return mimes[!~idx ? tmp : tmp.substring(++idx)];
487
- }
488
-
489
- const noop = () => {};
490
-
491
- function isMatch(uri, arr) {
492
- for (let i=0; i < arr.length; i++) {
493
- if (arr[i].test(uri)) return true;
494
- }
495
- }
496
-
497
- function toAssume(uri, extns) {
498
- let i=0, x, len=uri.length - 1;
499
- if (uri.charCodeAt(len) === 47) {
500
- uri = uri.substring(0, len);
501
- }
502
-
503
- let arr=[], tmp=`${uri}/index`;
504
- for (; i < extns.length; i++) {
505
- x = extns[i] ? `.${extns[i]}` : '';
506
- if (uri) arr.push(uri + x);
507
- arr.push(tmp + x);
508
- }
509
-
510
- return arr;
511
- }
512
-
513
- function viaCache(cache, uri, extns) {
514
- let i=0, data, arr=toAssume(uri, extns);
515
- for (; i < arr.length; i++) {
516
- if (data = cache[arr[i]]) return data;
517
- }
518
- }
519
-
520
- function viaLocal(dir, isEtag, uri, extns) {
521
- let i=0, arr=toAssume(uri, extns);
522
- let abs, stats, name, headers;
523
- for (; i < arr.length; i++) {
524
- abs = normalize(join(dir, name=arr[i]));
525
- if (abs.startsWith(dir) && fs.existsSync(abs)) {
526
- stats = fs.statSync(abs);
527
- if (stats.isDirectory()) continue;
528
- headers = toHeaders(name, stats, isEtag);
529
- headers['Cache-Control'] = isEtag ? 'no-cache' : 'no-store';
530
- return { abs, stats, headers };
531
- }
532
- }
533
- }
534
-
535
- function is404(req, res) {
536
- return (res.statusCode=404,res.end());
537
- }
538
-
539
- function send(req, res, file, stats, headers) {
540
- let code=200, tmp, opts={};
541
- headers = { ...headers };
542
-
543
- for (let key in headers) {
544
- tmp = res.getHeader(key);
545
- if (tmp) headers[key] = tmp;
546
- }
547
-
548
- if (tmp = res.getHeader('content-type')) {
549
- headers['Content-Type'] = tmp;
550
- }
551
-
552
- if (req.headers.range) {
553
- code = 206;
554
- let [x, y] = req.headers.range.replace('bytes=', '').split('-');
555
- let end = opts.end = parseInt(y, 10) || stats.size - 1;
556
- let start = opts.start = parseInt(x, 10) || 0;
557
-
558
- if (start >= stats.size || end >= stats.size) {
559
- res.setHeader('Content-Range', `bytes */${stats.size}`);
560
- res.statusCode = 416;
561
- return res.end();
562
- }
563
-
564
- headers['Content-Range'] = `bytes ${start}-${end}/${stats.size}`;
565
- headers['Content-Length'] = (end - start + 1);
566
- headers['Accept-Ranges'] = 'bytes';
567
- }
568
-
569
- res.writeHead(code, headers);
570
- fs.createReadStream(file, opts).pipe(res);
571
- }
572
-
573
- const ENCODING = {
574
- '.br': 'br',
575
- '.gz': 'gzip',
576
- };
577
-
578
- function toHeaders(name, stats, isEtag) {
579
- let enc = ENCODING[name.slice(-3)];
580
-
581
- let ctype = lookup(name.slice(0, enc && -3)) || '';
582
- if (ctype === 'text/html') ctype += ';charset=utf-8';
583
-
584
- let headers = {
585
- 'Content-Length': stats.size,
586
- 'Content-Type': ctype,
587
- 'Last-Modified': stats.mtime.toUTCString(),
588
- };
589
-
590
- if (enc) headers['Content-Encoding'] = enc;
591
- if (isEtag) headers['ETag'] = `W/"${stats.size}-${stats.mtime.getTime()}"`;
592
-
593
- return headers;
594
- }
595
-
596
- function sirv (dir, opts={}) {
597
- dir = resolve(dir || '.');
598
-
599
- let isNotFound = opts.onNoMatch || is404;
600
- let setHeaders = opts.setHeaders || noop;
601
-
602
- let extensions = opts.extensions || ['html', 'htm'];
603
- let gzips = opts.gzip && extensions.map(x => `${x}.gz`).concat('gz');
604
- let brots = opts.brotli && extensions.map(x => `${x}.br`).concat('br');
605
-
606
- const FILES = {};
607
-
608
- let fallback = '/';
609
- let isEtag = !!opts.etag;
610
- let isSPA = !!opts.single;
611
- if (typeof opts.single === 'string') {
612
- let idx = opts.single.lastIndexOf('.');
613
- fallback += !!~idx ? opts.single.substring(0, idx) : opts.single;
614
- }
615
-
616
- let ignores = [];
617
- if (opts.ignores !== false) {
618
- ignores.push(/[/]([A-Za-z\s\d~$._-]+\.\w+){1,}$/); // any extn
619
- if (opts.dotfiles) ignores.push(/\/\.\w/);
620
- else ignores.push(/\/\.well-known/);
621
- [].concat(opts.ignores || []).forEach(x => {
622
- ignores.push(new RegExp(x, 'i'));
623
- });
624
- }
625
-
626
- let cc = opts.maxAge != null && `public,max-age=${opts.maxAge}`;
627
- if (cc && opts.immutable) cc += ',immutable';
628
- else if (cc && opts.maxAge === 0) cc += ',must-revalidate';
629
-
630
- if (!opts.dev) {
631
- totalist(dir, (name, abs, stats) => {
632
- if (/\.well-known[\\+\/]/.test(name)) ; // keep
633
- else if (!opts.dotfiles && /(^\.|[\\+|\/+]\.)/.test(name)) return;
634
-
635
- let headers = toHeaders(name, stats, isEtag);
636
- if (cc) headers['Cache-Control'] = cc;
637
-
638
- FILES['/' + name.normalize().replace(/\\+/g, '/')] = { abs, stats, headers };
639
- });
640
- }
641
-
642
- let lookup = opts.dev ? viaLocal.bind(0, dir, isEtag) : viaCache.bind(0, FILES);
643
-
644
- return function (req, res, next) {
645
- let extns = [''];
646
- let pathname = parse(req).pathname;
647
- let val = req.headers['accept-encoding'] || '';
648
- if (gzips && val.includes('gzip')) extns.unshift(...gzips);
649
- if (brots && /(br|brotli)/i.test(val)) extns.unshift(...brots);
650
- extns.push(...extensions); // [...br, ...gz, orig, ...exts]
651
-
652
- if (pathname.indexOf('%') !== -1) {
653
- try { pathname = decodeURIComponent(pathname); }
654
- catch (err) { /* malform uri */ }
655
- }
656
-
657
- let data = lookup(pathname, extns) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns);
658
- if (!data) return next ? next() : isNotFound(req, res);
659
-
660
- if (isEtag && req.headers['if-none-match'] === data.headers['ETag']) {
661
- res.writeHead(304);
662
- return res.end();
663
- }
664
-
665
- if (gzips || brots) {
666
- res.setHeader('Vary', 'Accept-Encoding');
667
- }
668
-
669
- setHeaders(res, pathname, data.stats);
670
- send(req, res, data.abs, data.stats, data.headers);
671
- };
672
- }
673
-
674
23
  /** @param {string} dir */
675
24
  const mutable = (dir) =>
676
25
  sirv(dir, {
@@ -753,18 +102,20 @@ async function preview({
753
102
  return res.end(err.reason || 'Invalid request body');
754
103
  }
755
104
 
756
- const rendered =
757
- initial_url.startsWith(config.kit.paths.base) &&
758
- (await app.render({
759
- url: initial_url,
760
- method: req.method,
761
- headers: /** @type {import('types/helper').RequestHeaders} */ (req.headers),
762
- rawBody: body
763
- }));
764
-
765
- if (rendered) {
766
- res.writeHead(rendered.status, rendered.headers);
767
- if (rendered.body) res.write(rendered.body);
105
+ if (initial_url.startsWith(config.kit.paths.base)) {
106
+ const protocol = use_https ? 'https' : 'http';
107
+ const host = req.headers['host'];
108
+
109
+ const rendered = await app.render(
110
+ new Request(`${protocol}://${host}${initial_url}`, {
111
+ method: req.method,
112
+ headers: to_headers(req.headers),
113
+ body
114
+ })
115
+ );
116
+
117
+ res.writeHead(rendered.status, Object.fromEntries(rendered.headers));
118
+ if (rendered.body) res.write(new Uint8Array(await rendered.arrayBuffer()));
768
119
  res.end();
769
120
  } else {
770
121
  res.statusCode = 404;