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

Commit 069bf73

Browse files
hacdiasachingbrain
authored andcommitted
feat: evergreen web ui (#2520)
Switch to loading web ui from IPNS name so it's always the latest. Relevant release notes can be found at https://github.com/ipfs-shipyard/ipfs-webui/releases
1 parent 220d1f0 commit 069bf73

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
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

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

3-
const Joi = require('@hapi/joi')
4-
const resources = require('../../gateway/resources')
3+
const multiaddr = require('multiaddr')
4+
const debug = require('debug')
5+
const log = debug('ipfs:webui:info')
6+
log.error = debug('ipfs:webui:error')
57

68
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-
},
259
{
2610
method: '*',
2711
path: '/webui',
28-
handler (request, h) {
29-
return h.redirect('/ipfs/QmPURAjo3oneGH53ovt68UZEBvsc8nNmEhQZEpsVEQUMZE')
12+
async handler (request, h) {
13+
let scheme = 'http'
14+
let port
15+
let host
16+
17+
try {
18+
const { ipfs } = request.server.app
19+
const gateway = await ipfs.config.get('Addresses.Gateway')
20+
const address = multiaddr(gateway).nodeAddress()
21+
22+
port = address.port
23+
host = address.host
24+
} catch (err) {
25+
// may not have gateway configured
26+
log.error(err)
27+
28+
scheme = 'https'
29+
port = 443
30+
host = 'gateway.ipfs.io'
31+
}
32+
33+
return h.redirect(`${scheme}://${host}:${port}/ipns/webui.ipfs.io`)
3034
}
3135
}
3236
]

0 commit comments

Comments
 (0)