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

feat: webui v2.7.5, with feeling #2984

Merged
merged 3 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/ipfs/src/http/api/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

const Boom = require('@hapi/boom')

const METHODS = [
// RPC API requires POST, we block every other method
const BLOCKED_METHODS = [
'GET',
'PUT',
'PATCH',
Expand All @@ -27,7 +28,6 @@ const routes = [
...require('./files'),
...require('./pubsub'),
require('./debug'),
...require('./webui'),
...require('./dag'),
require('./dns'),
...require('./key'),
Expand All @@ -37,13 +37,15 @@ const routes = [
...require('./dht')
]

const extraRoutes = []
// webui is loaded from API port, but works over GET (not a part of RPC API)
const extraRoutes = [...require('./webui')]

const handler = () => {
throw Boom.methodNotAllowed()
}

METHODS.forEach(method => {
// add routes that return HTTP 504 for non-POST requests to RPC API
BLOCKED_METHODS.forEach(method => {
routes.forEach(route => {
extraRoutes.push({
method,
Expand Down
43 changes: 19 additions & 24 deletions packages/ipfs/src/http/api/routes/webui.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
'use strict'

const multiaddr = require('multiaddr')
const debug = require('debug')
const { gateway } = require('../../gateway/resources')
const log = debug('ipfs:webui:info')
log.error = debug('ipfs:webui:error')

const webuiCid = 'bafybeigxqbvc6qxk2wkdyzpkh7mr7zh5pxbvpjb6a6mxdtpwhlqaf4qj5a' // v2.7.4
Copy link
Member Author

@lidel lidel Apr 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jessicaschilling FYI in the future, when we release new ipfs-webui we will need to update only this one line 🤞

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lidel Is this the new version of the (broken link) js-ipfs file that appears here? https://github.com/ipfs-shipyard/ipfs-webui#releasing-a-new-version-of-the-webui

Copy link
Member Author

@lidel lidel Apr 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jessicaschilling Yes. I'll update that README when we finish the release dance for v2.7.4


module.exports = [
{
method: '*',
path: '/webui',
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.address
} catch (err) {
// may not have gateway configured
log.error(err)

scheme = 'https'
port = 443
host = 'gateway.ipfs.io'
method: 'GET',
path: `/ipfs/${webuiCid}/{path*}`, // only the whitelisted webui is allowed on API port
options: {
handler: gateway.handler,
response: {
ranges: false // disable built-in support, handler does it manually
},
ext: {
onPostHandler: { method: gateway.afterHandler }
}

return h.redirect(`${scheme}://${host}:${port}/ipfs/Qmexhq2sBHnXQbvyP2GfUdbnY7HCagH2Mw5vUNSBn2nxip`)
}
},
{
method: 'GET',
path: '/webui/{slug?}', // optional slug makes it work with and without slash
handler (request, h) {
return h.redirect(`/ipfs/${webuiCid}/`)
}
}
]