-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
41 lines (34 loc) · 995 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
/* eslint-disable no-process-env */
'use strict';
const express = require('express');
const morgan = require('morgan');
const _ = require('lodash');
const app = express();
const config = require('config');
const logger = require('./logger');
morgan.token('id', req => _.get(req, 'session.id', 'filevault'));
app.use(morgan('sessionId=:id ' + morgan.combined, {
stream: logger.stream,
skip: (req, res) => !process.env.DEBUG &&
(
res.statusCode >= 300 || !_.get(req, 'session.id') ||
['/healthz'].some(v => req.originalUrl.includes(v))
)
}));
app.use('/file', require('./controllers/file'));
/* eslint-disable no-unused-vars */
app.use((err, req, res, next) => {
/* eslint-enable no-unused-vars */
if (err.code) {
res.status(400);
} else {
res.status(500);
}
res.json(err);
});
module.exports.start = () => {
app.listen(config.get('port'), () => {
logger.info(`Server started on port ${config.get('port')}`);
});
};
module.exports.app = app;