feat(assist-server): added host configuration

This commit is contained in:
Alexander 2025-04-04 15:09:37 +02:00
parent dc975bc19a
commit 8b3be469b6

View file

@ -33,7 +33,6 @@ const getCompressionConfig = function () {
};
}
// Create a Socket.IO server with uWebSockets.js adapter
const io = new Server({
maxHttpBufferSize: (parseFloat(process.env.maxHttpBufferSize) || 5) * 1e6,
pingInterval: pingInterval, // Will use it for cache invalidation
@ -46,22 +45,19 @@ const io = new Server({
...getCompressionConfig()
});
// Middleware for Socket.IO to check authorization
io.use(async (socket, next) => await authorizer.check(socket, next));
// Socket.IO connection handler
io.on('connection', (socket) => onConnect(socket));
// Attach Socket.IO to uWebSockets.js
io.attachApp(app);
io.engine.on("headers", (headers) => {
headers["x-host-id"] = process.env.HOSTNAME || "unknown";
});
setSocketIOServer(io);
// Start the server
const HOST = process.env.LISTEN_HOST || '0.0.0.0';
const PORT = process.env.PORT || 3000;
app.listen(PORT, (token) => {
if (token) {
console.log(`Server running at http://localhost:${PORT}`);
console.log(`Server running at http://${HOST}:${PORT}`);
} else {
console.log(`Failed to listen on port ${PORT}`);
}