Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ app.use(session({
}
}));

// catch 404 and forward to error handler
app.use((req, res, next) => {
const err = new Error('Not Found');
err.status = 404;
next(err);
});

// Error handler
app.use((err, req, res, next) => {
res.statusCode = 500;
// Do not expose your error in production
res.json({ error: err.message });
next();
});

app.listen(process.env.PORT || config.port, async () => {
try {
const db = await connectDB();
Expand All @@ -48,4 +63,20 @@ app.listen(process.env.PORT || config.port, async () => {
}
});

export default app;

// Graceful shutdown
process.on('SIGTERM', () => {
// clearInterval(metricsInterval);

server.close((err) => {
if (err) {
console.error(err);
process.exit(1);
}

process.exit(0);
});
});


export default app;