Skip to content

Commit

Permalink
feat: support /ipns/ at HTTP Gateway
Browse files Browse the repository at this point in the history
It requires below to land first:
ipfs#1918

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
lidel committed May 6, 2019
1 parent 373eedc commit 752e904
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/http/api/routes/webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const resources = require('../../gateway/resources')
module.exports = [
{
method: '*',
path: '/ipfs/{cid*}',
path: '/ipfs/{immutableId*}',
options: {
pre: [
{ method: resources.gateway.checkCID, assign: 'args' }
{ method: resources.gateway.checkImmutableId, assign: 'args' }
]
},
handler: resources.gateway.handler
Expand Down
13 changes: 9 additions & 4 deletions src/http/gateway/resources/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ class ResponseStream extends PassThrough {
}

module.exports = {
checkCID (request, h) {
if (!request.params.cid) {
checkImmutableId (request, h) {
if (!request.params.immutableId) {
throw Boom.badRequest('Path Resolve error: path must contain at least one component')
}

return { ref: `/ipfs/${request.params.cid}` }
return { ref: `/ipfs/${request.params.immutableId}` }
},
checkMutableId (request, h) {
if (!request.params.mutableId) {
throw Boom.badRequest('Path Resolve error: path must contain at least one component')
}
return { ref: `/ipns/${request.params.mutableId}` }
},

async handler (request, h) {
Expand Down
46 changes: 32 additions & 14 deletions src/http/gateway/routes/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,37 @@

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

module.exports = {
method: '*',
path: '/ipfs/{cid*}',
options: {
handler: resources.gateway.handler,
pre: [
{ method: resources.gateway.checkCID, assign: 'args' }
],
response: {
ranges: false // disable built-in support, we do it manually
},
ext: {
onPostHandler: { method: resources.gateway.afterHandler }
module.exports = [
{
method: '*',
path: '/ipfs/{immutableId*}',
options: {
handler: resources.gateway.handler,
pre: [
{ method: resources.gateway.checkImmutableId, assign: 'args' }
],
response: {
ranges: false // disable built-in support, we do it manually
},
ext: {
onPostHandler: { method: resources.gateway.afterHandler }
}
}
},
{
method: '*',
path: '/ipns/{mutableId*}',
options: {
handler: resources.gateway.handler,
pre: [
{ method: resources.gateway.checkMutableId, assign: 'args' }
],
response: {
ranges: false // disable built-in support, we do it manually
},
ext: {
onPostHandler: { method: resources.gateway.afterHandler }
}
}
}
}
]
2 changes: 1 addition & 1 deletion src/http/gateway/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict'

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

0 comments on commit 752e904

Please sign in to comment.