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.
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
- Loading branch information
1 parent
220d1f0
commit 069bf73
Showing
2 changed files
with
28 additions
and
24 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,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`) | ||
} | ||
} | ||
] |