-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
38 lines (30 loc) · 1021 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
const express = require('express');
const cors = require('cors');
const validator = require('express-validator');
const isUuid = require('is-uuid');
// const ApiRateLimiter = require('express-rate-limit');
const {RateLimiter} = require('./src/services/rateLimiter');
const app = express();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(validator({customValidators: {}}));
app.enable('trust proxy');
const apiRateLimiter = RateLimiter({
windowMs: 60000, // 1 min
max: 500
});
app.use(apiRateLimiter); // global api rate limiter
app.set('RateLimiter', RateLimiter);
// initial router
require('./src/router/index')(app);
// error handler
app.use(function(err, req, res, next) {
console.error('application intenel error : ', err);
// set locals, only providing error in development
res.locals.message = err.message;
// render the error page/,
res.status(err.status || 500);
res.json({err: 'ServerError'});
});
module.exports = app;