fix(web): change port to 3007, add auto port cleanup, graceful error handling

This commit is contained in:
2026-05-07 03:26:22 +08:00
parent 001dbde9f4
commit c257dd2b8c
6 changed files with 46 additions and 3 deletions

View File

@@ -25,8 +25,20 @@ app.use('/api/configs', configsRouter);
wss.on('connection', handleChat);
const PORT = 3001;
const PORT = 3007;
initDb();
server.on('error', (err: NodeJS.ErrnoException) => {
if (err.code === 'EADDRINUSE') {
console.error(`Port ${PORT} is in use. Run: npx kill-port ${PORT}`);
process.exit(1);
}
throw err;
});
server.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});
process.on('SIGTERM', () => { server.close(); process.exit(0); });
process.on('SIGINT', () => { server.close(); process.exit(0); });