mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-03-13 01:47:24 +00:00
fix: use src hostname for redirecting to Vite in development
Previously, the server redirected to Vite using `localhost` as the hostname. Even if the user was using HOST="0.0.0.0", if they connected to server from another device on the same network using `http://<host_ip>:3001`, the server would redirect them to `http://localhost:5173`, which would not work since `localhost` would resolve to the client's machine instead of the server.
This commit is contained in:
@@ -2401,7 +2401,7 @@ app.get('*', (req, res) => {
|
||||
res.sendFile(indexPath);
|
||||
} else {
|
||||
// In development, redirect to Vite dev server only if dist doesn't exist
|
||||
res.redirect(`http://localhost:${process.env.VITE_PORT || 5173}`);
|
||||
res.redirect(`${req.protocol}://${req.hostname}:${VITE_PORT}`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2493,6 +2493,7 @@ const PORT = process.env.PORT || 3001;
|
||||
const HOST = process.env.HOST || '0.0.0.0';
|
||||
// Show localhost in URL when binding to all interfaces (0.0.0.0 isn't a connectable address)
|
||||
const DISPLAY_HOST = HOST === '0.0.0.0' ? 'localhost' : HOST;
|
||||
const VITE_PORT = process.env.VITE_PORT || 5173;
|
||||
|
||||
// Initialize database and start server
|
||||
async function startServer() {
|
||||
@@ -2509,7 +2510,7 @@ async function startServer() {
|
||||
console.log(`${c.info('[INFO]')} Running in ${c.bright(isProduction ? 'PRODUCTION' : 'DEVELOPMENT')} mode`);
|
||||
|
||||
if (!isProduction) {
|
||||
console.log(`${c.warn('[WARN]')} Note: Requests will be proxied to Vite dev server at ${c.dim('http://localhost:' + (process.env.VITE_PORT || 5173))}`);
|
||||
console.log(`${c.warn('[WARN]')} Note: Requests will be proxied to Vite dev server at ${c.dim('http://localhost:' + VITE_PORT)}`);
|
||||
}
|
||||
|
||||
server.listen(PORT, HOST, async () => {
|
||||
|
||||
Reference in New Issue
Block a user