Add server startup logging
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"start": "node build/index.js",
|
"start": "node build/index.js",
|
||||||
"dev": "tsx watch --clear-screen=false src/index.ts"
|
"dev": "node --import tsx --watch --watch-preserve-output src/index.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/cors": "^2.8.17",
|
"@types/cors": "^2.8.17",
|
||||||
|
|||||||
@@ -152,4 +152,36 @@ app.get("/config", (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
app.listen(PORT, () => {});
|
|
||||||
|
try {
|
||||||
|
const server = app.listen(PORT);
|
||||||
|
|
||||||
|
server.on('listening', () => {
|
||||||
|
const addr = server.address();
|
||||||
|
const port = typeof addr === 'string' ? addr : addr?.port;
|
||||||
|
console.log(`Server listening on port ${port}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
server.on('error', (error: any) => {
|
||||||
|
if (error.code === 'EADDRINUSE') {
|
||||||
|
console.error(`Port ${PORT} is already in use`);
|
||||||
|
process.exit(1);
|
||||||
|
} else {
|
||||||
|
console.error('Error starting server:', error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('uncaughtException', (error) => {
|
||||||
|
console.error('Uncaught exception:', error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('unhandledRejection', (error) => {
|
||||||
|
console.error('Unhandled rejection:', error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to start server:', error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user