From 069bf73d40062be6ec20309c53ace32bbb71e603 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Tue, 15 Oct 2019 12:03:17 +0100 Subject: [PATCH] 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 --- src/cli/commands/daemon.js | 4 +-- src/http/api/routes/webui.js | 48 +++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/cli/commands/daemon.js b/src/cli/commands/daemon.js index 6ca2193cf6..3c3bbec345 100644 --- a/src/cli/commands/daemon.js +++ b/src/cli/commands/daemon.js @@ -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`) diff --git a/src/http/api/routes/webui.js b/src/http/api/routes/webui.js index b104c086ef..d97e3b3d4e 100644 --- a/src/http/api/routes/webui.js +++ b/src/http/api/routes/webui.js @@ -1,32 +1,36 @@ 'use strict' -const Joi = require('@hapi/joi') -const resources = require('../../gateway/resources') +const multiaddr = require('multiaddr') +const debug = require('debug') +const log = debug('ipfs:webui:info') +log.error = debug('ipfs:webui:error') 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('/ipfs/QmPURAjo3oneGH53ovt68UZEBvsc8nNmEhQZEpsVEQUMZE') + async handler (request, h) { + let scheme = 'http' + let port + let host + + try { + const { ipfs } = request.server.app + const gateway = await ipfs.config.get('Addresses.Gateway') + const address = multiaddr(gateway).nodeAddress() + + port = address.port + host = address.host + } catch (err) { + // may not have gateway configured + log.error(err) + + scheme = 'https' + port = 443 + host = 'gateway.ipfs.io' + } + + return h.redirect(`${scheme}://${host}:${port}/ipns/webui.ipfs.io`) } } ]