feat: implement one-port WebSocket server with updated connection handling and configuration

This commit is contained in:
MythEclipse
2026-05-13 17:49:33 +07:00
parent f9a4b4a92d
commit 0e056732bc
5 changed files with 188 additions and 19 deletions
+3 -1
View File
@@ -24,7 +24,9 @@ const configSchema = z.object({
AUDIO_CHANNELS: z.coerce.number().positive().default(2),
AVATAR_SIZE: z.coerce.number().positive().default(64),
LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]).default("info"),
NODE_ENV: z.enum(["development", "production"]).default("development"),
NODE_ENV: z
.enum(["development", "production", "test"])
.default("development"),
});
export type AppConfig = z.infer<typeof configSchema>;
+4 -4
View File
@@ -46,9 +46,9 @@ export function startWebserver(port: number = 3000) {
const app = express();
const server = http.createServer(app);
const wsPort = port + 1;
const wss = new WebSocketServer({ port: wsPort, host: "0.0.0.0" });
wsLogger.info({ wsPort }, "WebSocket server listening");
const wsPath = "/ws";
const wss = new WebSocketServer({ server, path: wsPath });
wsLogger.info({ port, wsPath }, "WebSocket server listening");
// Security headers
app.use(helmet());
@@ -199,7 +199,7 @@ export function startWebserver(port: number = 3000) {
}, 20);
wss.on("connection", (ws) => {
wsLogger.info({ wsPort }, "New WebSocket connection");
wsLogger.info({ port, wsPath }, "New WebSocket connection");
wsClients.add(ws);
ws.send(