Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: redirect to the gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Oct 8, 2019
1 parent 60eedb2 commit 7b6ea44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/cli/commands/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ module.exports = {
try {
await daemon.start()
daemon._httpApi._apiServers.forEach(apiServer => {
print(`API listening on ${apiServer.info.ma.toString()}`)
print(`API listening on ${apiServer.info.ma}`)
})
daemon._httpApi._gatewayServers.forEach(gatewayServer => {
print(`Gateway (read only) listening on ${gatewayServer.info.ma.toString()}`)
print(`Gateway (read only) listening on ${gatewayServer.info.ma}`)
})
daemon._httpApi._apiServers.forEach(apiServer => {
print(`Web UI available at ${toUri(apiServer.info.ma)}/webui`)
Expand Down
33 changes: 11 additions & 22 deletions src/http/api/routes/webui.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
'use strict'

const Joi = require('@hapi/joi')
const resources = require('../../gateway/resources')
const multiaddr = require('multiaddr')

module.exports = [
{
method: '*',
path: '/ipfs/{path*}',
options: {
handler: resources.gateway.handler,
validate: {
params: {
path: Joi.string().required()
}
},
response: {
ranges: false // disable built-in support, handler does it manually
},
ext: {
onPostHandler: { method: resources.gateway.afterHandler }
}
}
},
{
method: '*',
path: '/webui',
handler (request, h) {
return h.redirect('/ipns/webui.ipfs.io')
async handler (request, h) {
const { ipfs } = request.server.app
const gateway = await ipfs.config.get('Addresses.Gateway')
const addr = multiaddr(gateway)
const {
port,
address
} = addr.nodeAddress()

return h.redirect(`http://${address}:${port}/ipns/webui.ipfs.io`)
}
}
]

0 comments on commit 7b6ea44

Please sign in to comment.