-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (29 loc) · 960 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const express = require('express');
const morgan = require('morgan');
const devLogger = require('./lib/devLogger');
const mainRouter = require('./routes/mainRouter');
const store = require('./db/mongo');
store.init();
const env = process.env.NODE_ENV || 'development';
const app = express();
// security through obscurity \o/
app.disable('x-powered-by');
// logging middleware for dev environment
if (env === 'development') app.use(morgan('dev'));
app.use(express.json());
// invoke router for all requests
app.use('/', mainRouter);
// shut down gracefully on any uncaught runtime exceptions
process.on('uncaughtException', async (err) => {
devLogger(err);
await store.shutdown();
process.exit(1);
});
// for now, also exit on any unhandled promise rejections, might need to
// research this a bit more
process.on('unhandledRejection', async (err) => {
devLogger(err);
await store.shutdown();
process.exit(1);
});
module.exports = app;