-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (36 loc) · 999 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
42
43
44
const express = require('express');
const logger = require('morgan');
const bodyParser = require('body-parser');
const routes = require('./routes');
const cors = require('cors');
const compression = require('compression');
const app = express();
app.disable('x-powered-by');
app.use ((req, res, next) => {
req.ipData = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
next();
});
app.use(compression())
app.use(cors({
exposedHeaders: ['proof'],
}));
app.use(logger('dev', { skip: () => app.get('env') === 'test' }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// Routes
app.use('', routes);
// Catch 404 and forward to error handler
app.use((req, res, next) => {
const err = new Error('Not Found');
err.status = 404;
next(err);
});
// Error handler
app.use((err, req, res, next) => { // eslint-disable-line no-unused-vars
res
.status(err.status || 500)
.render('error', {
message: err.message
});
});
module.exports = app;