-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
37 lines (28 loc) · 917 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
const path = require('path');
const helmet = require('helmet');
const morgan = require('morgan');
const express = require('express');
const routes = require('./routes');
const utils = require('./lib/utils');
const favicon = require('serve-favicon');
const bodyParser = require('body-parser');
const jsonResponse = require('./middleware/response');
const errorHandler = require('./middleware/error-handler');
const { logger } = utils;
const app = express();
app.set('port', process.env.PORT || 3000);
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(helmet());
app.use(morgan('tiny'));
app.use(bodyParser.json());
app.use(jsonResponse);
app.use('/api', routes);
app.use(errorHandler);
app.use((req, res) => res.forbidden());
/**
* Listen for connections.
*/
app.listen(app.get('port'), () => {
logger.info('Node app is running on port', app.get('port'));
});
module.exports = app;