-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
50 lines (35 loc) · 1.07 KB
/
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
45
46
47
48
49
import express from 'express';
import compression from 'compression';
import cors from 'cors';
import helmet from 'helmet';
import mongoSanitize from 'express-mongo-sanitize';
import morgan from 'morgan';
import bodyParser from 'body-parser';
import routes from './routes/index.js';
import error from './middlewares/error.js';
const app= express();
// app.get('/favicon.ico', (req, res) => res.status(204));
if (process.env.NODE_ENV !== 'production') {
app.use(morgan('dev'));
}
app.use(helmet());
// parse json request body
app.use(bodyParser.json());
// parse urlencoded request body
app.use(bodyParser.urlencoded({ extended: true }));
// sanitize request data
app.use(mongoSanitize());
// gzip compression
app.use(compression());
// enable cors
app.use(cors());
// app.options('*', cors);
// v1 api routes
app.use('/v1', routes);
// if error is not an instanceOf APIError, convert it.
app.use(error.converter);
// catch 404 and forward to error handler
app.use(error.notFound);
// error handler, send stacktrace only during development
app.use(error.handler);
export default app;