Update index.js

This commit is contained in:
viper151
2025-07-13 15:22:34 +02:00
committed by GitHub
parent 9f65756e2c
commit 2d63b18c69

View File

@@ -130,18 +130,6 @@ async function setupProjectsWatcher() {
}
}
// Get the first non-localhost IP address
function getServerIP() {
const interfaces = os.networkInterfaces();
for (const name of Object.keys(interfaces)) {
for (const iface of interfaces[name]) {
if (iface.family === 'IPv4' && !iface.internal) {
return iface.address;
}
}
}
return 'localhost';
}
const app = express();
const server = http.createServer(app);
@@ -188,9 +176,7 @@ app.use(express.static(path.join(__dirname, '../dist')));
// API Routes (protected)
app.get('/api/config', authenticateToken, (req, res) => {
// Always use the server's actual IP and port for WebSocket connections
const serverIP = getServerIP();
const host = `${serverIP}:${PORT}`;
const host = req.headers.host || `${req.hostname}:${PORT}`;
const protocol = req.protocol === 'https' || req.get('x-forwarded-proto') === 'https' ? 'wss' : 'ws';
console.log('Config API called - Returning host:', host, 'Protocol:', protocol);
@@ -1006,4 +992,4 @@ async function startServer() {
}
}
startServer();
startServer();