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

Commit 133911d

Browse files
committed
fix: redirect to the gateway
1 parent 60eedb2 commit 133911d

File tree

3 files changed

+13
-25
lines changed

3 files changed

+13
-25
lines changed

src/cli/commands/daemon.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ module.exports = {
7979
try {
8080
await daemon.start()
8181
daemon._httpApi._apiServers.forEach(apiServer => {
82-
print(`API listening on ${apiServer.info.ma.toString()}`)
82+
print(`API listening on ${apiServer.info.ma}`)
8383
})
8484
daemon._httpApi._gatewayServers.forEach(gatewayServer => {
85-
print(`Gateway (read only) listening on ${gatewayServer.info.ma.toString()}`)
85+
print(`Gateway (read only) listening on ${gatewayServer.info.ma}`)
8686
})
8787
daemon._httpApi._apiServers.forEach(apiServer => {
8888
print(`Web UI available at ${toUri(apiServer.info.ma)}/webui`)

src/http/api/routes/webui.js

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

3-
const Joi = require('@hapi/joi')
4-
const resources = require('../../gateway/resources')
3+
const multiaddr = require('multiaddr')
54

65
module.exports = [
7-
{
8-
method: '*',
9-
path: '/ipfs/{path*}',
10-
options: {
11-
handler: resources.gateway.handler,
12-
validate: {
13-
params: {
14-
path: Joi.string().required()
15-
}
16-
},
17-
response: {
18-
ranges: false // disable built-in support, handler does it manually
19-
},
20-
ext: {
21-
onPostHandler: { method: resources.gateway.afterHandler }
22-
}
23-
}
24-
},
256
{
267
method: '*',
278
path: '/webui',
28-
handler (request, h) {
29-
return h.redirect('/ipns/webui.ipfs.io')
9+
async handler (request, h) {
10+
const { ipfs } = request.server.app
11+
const gateway = await ipfs.config.get('Addresses.Gateway')
12+
const addr = multiaddr(gateway)
13+
const {
14+
port,
15+
address
16+
} = addr.nodeAddress()
17+
18+
return h.redirect(`http://${address}:${port}/ipns/webui.ipfs.io`)
3019
}
3120
}
3221
]

src/http/gateway/resources/gateway.js

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ module.exports = {
4444
let ipfsPath = decodeURI(path.startsWith('/ipns/')
4545
? await ipfs.name.resolve(path, { recursive: true })
4646
: path)
47-
4847
let directory = false
4948
let data
5049
try {

0 commit comments

Comments
 (0)