@sveltejs/kit 1.0.0-next.351 → 1.0.0-next.354

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