Skip to content

Commit 32311ce

Browse files
Agentclaude
andcommitted
Fix IP redirect to use actual host IP from browser request
- Pass hostIP from HTTP request headers to installer config - Use req.hostname / req.headers.host instead of Docker gateway IP - Fixes redirect going to 172.18.0.1 (Docker gateway) instead of actual host - Now correctly redirects to the IP the browser connected to Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent e3ba80f commit 32311ce

2 files changed

Lines changed: 8 additions & 23 deletions

File tree

installer.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ export async function runInstaller(config, events) {
134134
});
135135
}
136136

137-
// Installation complete - detect host IP for redirect
138-
const hostIP = await getHostIP();
137+
// Installation complete - use host IP from config (detected from browser request)
138+
const hostIP = config.hostIP || 'localhost';
139139
events.emit('progress', {
140140
type: 'complete',
141141
url: `http://${hostIP}:8112`,
@@ -431,23 +431,3 @@ async function waitForHealthy(containerName, timeout, events) {
431431

432432
throw new Error(`${containerName} failed to become healthy within ${timeout}ms`);
433433
}
434-
435-
async function getHostIP() {
436-
try {
437-
// Get the gateway IP of the stdout container's network
438-
const { stdout } = await execFile('docker', [
439-
'inspect',
440-
'--format={{range .NetworkSettings.Networks}}{{.Gateway}}{{end}}',
441-
'stdout'
442-
]);
443-
const gatewayIP = stdout.trim();
444-
if (gatewayIP && gatewayIP !== '') {
445-
return gatewayIP;
446-
}
447-
} catch (err) {
448-
// Fallback: try to get host.docker.internal IP
449-
}
450-
451-
// Default fallback
452-
return 'localhost';
453-
}

server.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ app.get('/api/setup/stream', (req, res) => {
3737

3838
// If installation already completed, send completion immediately
3939
if (installationComplete) {
40-
res.write(`data: ${JSON.stringify({ type: 'complete', url: 'http://stdout.local:8112' })}\n\n`);
40+
const hostIP = req.hostname || req.headers.host?.split(':')[0] || 'localhost';
41+
res.write(`data: ${JSON.stringify({ type: 'complete', url: `http://${hostIP}:8112` })}\n\n`);
4142
res.end();
4243
return;
4344
}
@@ -76,6 +77,9 @@ app.post('/api/setup/start', async (req, res) => {
7677
return res.status(400).json({ error: 'License key required' });
7778
}
7879

80+
// Get host IP from the request (the IP the browser connected to)
81+
const hostIP = req.hostname || req.headers.host?.split(':')[0] || 'localhost';
82+
7983
res.json({ status: 'started' });
8084

8185
// Run installer in background
@@ -84,6 +88,7 @@ app.post('/api/setup/start', async (req, res) => {
8488
adminEmail,
8589
adminPassword,
8690
environmentName: environmentName || 'Production',
91+
hostIP,
8792
}, setupEvents).catch(err => {
8893
setupEvents.emit('progress', { type: 'error', error: err.message });
8994
});

0 commit comments

Comments
 (0)