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