fix(setup): print the hub's public URL, not the host the reader typed
The setup pages build commands that get pasted into a terminal on a *different* machine, but they built them from location.origin. Open the console by LAN IP or over a tunnel and the enrolment one-liner told the target machine to curl an address it may not resolve at all. /docs and /enroll/:token are now served through a template that stamps in config.baseUrl — PUBLIC_URL where set, the proxied request host otherwise — with location.origin left as a fallback for the unsubstituted file. The remaining 127.0.0.1 references are the loopback VNC port on the machine being registered, which is meant to be literal. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+5
-1
@@ -293,7 +293,11 @@
|
|||||||
|
|
||||||
<script src="/particles.js"></script>
|
<script src="/particles.js"></script>
|
||||||
<script>
|
<script>
|
||||||
const origin = location.origin;
|
// Substituted by the server with this hub's public address. These commands run
|
||||||
|
// on a different machine, so location.origin would be wrong whenever the reader
|
||||||
|
// reached this page by IP or over a tunnel. Falls back only if served unmodified.
|
||||||
|
const stamped = '__HUB__';
|
||||||
|
const origin = stamped.indexOf('__') === 0 ? location.origin : stamped;
|
||||||
|
|
||||||
const commands = {
|
const commands = {
|
||||||
'cmd-macos': `curl -fsSL ${origin}/install.sh?token=TOKEN | sh`,
|
'cmd-macos': `curl -fsSL ${origin}/install.sh?token=TOKEN | sh`,
|
||||||
|
|||||||
+6
-2
@@ -119,8 +119,12 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
const token = location.pathname.split('/').filter(Boolean).pop();
|
const token = location.pathname.split('/').filter(Boolean).pop();
|
||||||
const origin = location.origin;
|
|
||||||
const link = `${origin}/enroll/${token}`;
|
// Substituted by the server with this hub's public address — the commands below
|
||||||
|
// are pasted into a terminal on this machine and have to reach the hub by a name
|
||||||
|
// it can resolve, not by whatever host the reader used to open this page.
|
||||||
|
const stamped = '__HUB__';
|
||||||
|
const origin = stamped.indexOf('__') === 0 ? location.origin : stamped;
|
||||||
|
|
||||||
// The hub stamps its own address and this token into the install scripts, so
|
// The hub stamps its own address and this token into the install scripts, so
|
||||||
// each of these really is the whole command — nothing to fill in by hand.
|
// each of these really is the whole command — nothing to fill in by hand.
|
||||||
|
|||||||
+18
-2
@@ -120,9 +120,25 @@ app.get('/install.ps1', serveInstallScript('install.ps1', 'text/plain; charset=u
|
|||||||
app.use('/novnc', express.static(NOVNC_DIR, { maxAge: '7d', immutable: true }));
|
app.use('/novnc', express.static(NOVNC_DIR, { maxAge: '7d', immutable: true }));
|
||||||
app.use(express.static(PUBLIC_DIR));
|
app.use(express.static(PUBLIC_DIR));
|
||||||
|
|
||||||
|
// The setup pages print commands that get run on *another* machine, so they must
|
||||||
|
// name this hub's public address — not whatever host the reader happens to have
|
||||||
|
// typed. Reached over the LAN IP, `location.origin` would hand out a URL the
|
||||||
|
// target machine may not be able to resolve at all.
|
||||||
|
function sendPageWithHub(file) {
|
||||||
|
return (req, res) => {
|
||||||
|
let html;
|
||||||
|
try {
|
||||||
|
html = fs.readFileSync(path.join(PUBLIC_DIR, file), 'utf8');
|
||||||
|
} catch {
|
||||||
|
return res.status(500).type('text/plain').send(`${file} missing from this deployment`);
|
||||||
|
}
|
||||||
|
res.type('html').send(html.split('__HUB__').join(config.baseUrl(req)));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
app.get('/viewer', (_req, res) => res.sendFile(path.join(PUBLIC_DIR, 'viewer.html')));
|
app.get('/viewer', (_req, res) => res.sendFile(path.join(PUBLIC_DIR, 'viewer.html')));
|
||||||
app.get('/docs', (_req, res) => res.sendFile(path.join(PUBLIC_DIR, 'docs.html')));
|
app.get('/docs', sendPageWithHub('docs.html'));
|
||||||
app.get('/enroll/:token', (_req, res) => res.sendFile(path.join(PUBLIC_DIR, 'enroll.html')));
|
app.get('/enroll/:token', sendPageWithHub('enroll.html'));
|
||||||
app.get('/s/:token', (_req, res) => res.sendFile(path.join(PUBLIC_DIR, 'share.html')));
|
app.get('/s/:token', (_req, res) => res.sendFile(path.join(PUBLIC_DIR, 'share.html')));
|
||||||
|
|
||||||
app.use((req, res) => {
|
app.use((req, res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user