hypercore-fetch 9.1.0 → 9.3.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.
- package/index.js +26 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -27,6 +27,14 @@ const HEADER_LAST_MODIFIED = 'Last-Modified'
|
|
|
27
27
|
|
|
28
28
|
export const ERROR_KEY_NOT_CREATED = 'Must create key with POST before reading'
|
|
29
29
|
|
|
30
|
+
const INDEX_FILES = [
|
|
31
|
+
'index.html',
|
|
32
|
+
'index.md',
|
|
33
|
+
'index.gmi',
|
|
34
|
+
'index.gemini',
|
|
35
|
+
'README.md'
|
|
36
|
+
]
|
|
37
|
+
|
|
30
38
|
async function DEFAULT_RENDER_INDEX (url, files, fetch) {
|
|
31
39
|
return `
|
|
32
40
|
<!DOCTYPE html>
|
|
@@ -40,6 +48,11 @@ async function DEFAULT_RENDER_INDEX (url, files, fetch) {
|
|
|
40
48
|
`
|
|
41
49
|
}
|
|
42
50
|
|
|
51
|
+
// Support gemini files
|
|
52
|
+
mime.define({
|
|
53
|
+
'text/gemini': ['gmi', 'gemini']
|
|
54
|
+
}, true)
|
|
55
|
+
|
|
43
56
|
export default async function makeHyperFetch ({
|
|
44
57
|
sdk,
|
|
45
58
|
writable = false,
|
|
@@ -454,12 +467,15 @@ export default async function makeHyperFetch ({
|
|
|
454
467
|
}
|
|
455
468
|
|
|
456
469
|
if (!noResolve) {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
470
|
+
for (const indexFile of INDEX_FILES) {
|
|
471
|
+
if (entries.includes(indexFile)) {
|
|
472
|
+
const mimeType = getMimeType(indexFile)
|
|
473
|
+
return {
|
|
474
|
+
status: 204,
|
|
475
|
+
headers: {
|
|
476
|
+
...resHeaders,
|
|
477
|
+
[HEADER_CONTENT_TYPE]: mimeType
|
|
478
|
+
}
|
|
463
479
|
}
|
|
464
480
|
}
|
|
465
481
|
}
|
|
@@ -586,8 +602,10 @@ export default async function makeHyperFetch ({
|
|
|
586
602
|
}
|
|
587
603
|
|
|
588
604
|
if (!noResolve) {
|
|
589
|
-
|
|
590
|
-
|
|
605
|
+
for (const indexFile of INDEX_FILES) {
|
|
606
|
+
if (entries.includes(indexFile)) {
|
|
607
|
+
return serveFile(drive, posix.join(pathname, 'indexFile'), isRanged)
|
|
608
|
+
}
|
|
591
609
|
}
|
|
592
610
|
}
|
|
593
611
|
|