Skip to content

Commit 752e904

Browse files
committed
feat: support /ipns/ at HTTP Gateway
It requires below to land first: ipfs#1918 License: MIT Signed-off-by: Marcin Rataj <[email protected]>
1 parent 373eedc commit 752e904

File tree

4 files changed

+44
-21
lines changed

4 files changed

+44
-21
lines changed

src/http/api/routes/webui.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const resources = require('../../gateway/resources')
55
module.exports = [
66
{
77
method: '*',
8-
path: '/ipfs/{cid*}',
8+
path: '/ipfs/{immutableId*}',
99
options: {
1010
pre: [
11-
{ method: resources.gateway.checkCID, assign: 'args' }
11+
{ method: resources.gateway.checkImmutableId, assign: 'args' }
1212
]
1313
},
1414
handler: resources.gateway.handler

src/http/gateway/resources/gateway.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,17 @@ class ResponseStream extends PassThrough {
4545
}
4646

4747
module.exports = {
48-
checkCID (request, h) {
49-
if (!request.params.cid) {
48+
checkImmutableId (request, h) {
49+
if (!request.params.immutableId) {
5050
throw Boom.badRequest('Path Resolve error: path must contain at least one component')
5151
}
52-
53-
return { ref: `/ipfs/${request.params.cid}` }
52+
return { ref: `/ipfs/${request.params.immutableId}` }
53+
},
54+
checkMutableId (request, h) {
55+
if (!request.params.mutableId) {
56+
throw Boom.badRequest('Path Resolve error: path must contain at least one component')
57+
}
58+
return { ref: `/ipns/${request.params.mutableId}` }
5459
},
5560

5661
async handler (request, h) {

src/http/gateway/routes/gateway.js

+32-14
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,37 @@
22

33
const resources = require('../resources')
44

5-
module.exports = {
6-
method: '*',
7-
path: '/ipfs/{cid*}',
8-
options: {
9-
handler: resources.gateway.handler,
10-
pre: [
11-
{ method: resources.gateway.checkCID, assign: 'args' }
12-
],
13-
response: {
14-
ranges: false // disable built-in support, we do it manually
15-
},
16-
ext: {
17-
onPostHandler: { method: resources.gateway.afterHandler }
5+
module.exports = [
6+
{
7+
method: '*',
8+
path: '/ipfs/{immutableId*}',
9+
options: {
10+
handler: resources.gateway.handler,
11+
pre: [
12+
{ method: resources.gateway.checkImmutableId, assign: 'args' }
13+
],
14+
response: {
15+
ranges: false // disable built-in support, we do it manually
16+
},
17+
ext: {
18+
onPostHandler: { method: resources.gateway.afterHandler }
19+
}
20+
}
21+
},
22+
{
23+
method: '*',
24+
path: '/ipns/{mutableId*}',
25+
options: {
26+
handler: resources.gateway.handler,
27+
pre: [
28+
{ method: resources.gateway.checkMutableId, assign: 'args' }
29+
],
30+
response: {
31+
ranges: false // disable built-in support, we do it manually
32+
},
33+
ext: {
34+
onPostHandler: { method: resources.gateway.afterHandler }
35+
}
1836
}
1937
}
20-
}
38+
]

src/http/gateway/routes/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
'use strict'
22

3-
module.exports = [require('./gateway')]
3+
module.exports = [...require('./gateway')]

0 commit comments

Comments
 (0)