hypercore-fetch 9.2.0 → 9.3.1
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 +21 -8
- package/package.json +1 -1
- package/test.js +20 -0
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>
|
|
@@ -459,12 +467,15 @@ export default async function makeHyperFetch ({
|
|
|
459
467
|
}
|
|
460
468
|
|
|
461
469
|
if (!noResolve) {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
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
|
+
}
|
|
468
479
|
}
|
|
469
480
|
}
|
|
470
481
|
}
|
|
@@ -591,8 +602,10 @@ export default async function makeHyperFetch ({
|
|
|
591
602
|
}
|
|
592
603
|
|
|
593
604
|
if (!noResolve) {
|
|
594
|
-
|
|
595
|
-
|
|
605
|
+
for (const indexFile of INDEX_FILES) {
|
|
606
|
+
if (entries.includes(indexFile)) {
|
|
607
|
+
return serveFile(drive, posix.join(pathname, indexFile), isRanged)
|
|
608
|
+
}
|
|
596
609
|
}
|
|
597
610
|
}
|
|
598
611
|
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -333,6 +333,26 @@ test('Ignore index.html with noResolve', async (t) => {
|
|
|
333
333
|
const entries = await listDirRequest.json()
|
|
334
334
|
t.deepEqual(entries, ['index.html'], 'able to list index.html')
|
|
335
335
|
})
|
|
336
|
+
test('Render index.gmi', async (t) => {
|
|
337
|
+
const created = await nextURL(t)
|
|
338
|
+
const uploadLocation = new URL('./index.gmi', created)
|
|
339
|
+
|
|
340
|
+
const uploadResponse = await fetch(uploadLocation, {
|
|
341
|
+
method: 'put',
|
|
342
|
+
body: SAMPLE_CONTENT
|
|
343
|
+
})
|
|
344
|
+
await checkResponse(uploadResponse, t)
|
|
345
|
+
|
|
346
|
+
const uploadedContentResponse = await fetch(created)
|
|
347
|
+
|
|
348
|
+
await checkResponse(uploadedContentResponse, t)
|
|
349
|
+
|
|
350
|
+
const content = await uploadedContentResponse.text()
|
|
351
|
+
const contentType = uploadedContentResponse.headers.get('Content-Type')
|
|
352
|
+
|
|
353
|
+
t.equal(contentType, 'text/gemini; charset=utf-8', 'got HTML mime type')
|
|
354
|
+
t.equal(content, SAMPLE_CONTENT, 'loaded index.html content')
|
|
355
|
+
})
|
|
336
356
|
test('Read directory as HTML', async (t) => {
|
|
337
357
|
const created = await nextURL(t)
|
|
338
358
|
|