-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
32 lines (26 loc) · 799 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
const config = require('./config');
const loggerOpts = {
timestamp: () => `, "time": "${new Date().toISOString()}"`,
level: config.logLevel
};
const logger = require('pino')(loggerOpts);
const express = require('express');
const cors = require('cors');
const expressWs = require('express-ws');
const routes = require('./lib/routes/index');
const ws = require('./lib/ws/handler');
const app = express();
expressWs(app);
app.locals = app.locals || {};
app.locals = {
...app.locals,
logger
};
app.use(cors());
app.use('/', routes);
app.ws('/', ws);
app.use((err, req, res, next) => {
logger.error(err, 'burped error');
res.status(err.status || 500).json({msg: err.message});
});
app.listen(config.httpPort, () => logger.info(`listening for HTTP traffic on port ${config.httpPort}`));