This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: webui v2.7.5, with feeling (#2984)
- Loading branch information
Showing
2 changed files
with
25 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = 'bafybeidatpz2hli6fgu3zul5woi27ujesdf5o5a7bu622qj6ugharciwjq' // v2.7.5 | ||
|
||
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}/`) | ||
} | ||
} | ||
] |