-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (32 loc) · 882 Bytes
/
index.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 expressValidator = require('express-validator');
const routers = require('./routers');
const bodyParser = require('body-parser');
const logger = require('morgan');
const cors = require('cors');
const { NODE_ENV, PORT, SECRET_KEY } = require('./constants/config');
app = express();
app.set('port', PORT);
app.use(bodyParser.json({ jsonLimit: '50mb' }));
if (NODE_ENV === 'production') {
app.use(logger('combined'));
} else {
app.use(logger('dev'));
}
app.use(cors());
app.use(expressValidator());
app.use('/api', routers);
/**
* Error handler
*/
app.use((err, req, res, next) => {
res.status(err.status || 500);
res.json({
message: err.message,
errors: err.errors
});
});
const server = app.listen(PORT, function() {
console.log(`Server started on port ${PORT}`);
});
module.exports = app;