-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
46 lines (38 loc) · 1.37 KB
/
app.ts
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
process.env.NODE_ENV = process.env.NODE_ENV || 'dev';
import express = require('express');
require('module-alias/register');
import cors = require('cors');
import compression = require('compression');
import helmet = require('helmet');
import path = require('path');
import cookieParser = require('cookie-parser');
import logger = require('morgan');
import rateLimit = require('express-rate-limit');
const app: express.Application = express();
// Define request limiter per user to avoid DOS attack
const limiterOption: rateLimit.Options = {
windowMs: 15 * 60 * 1000, // 15 minutes
max: 20000 // limit each IP to 100 requests per windowMs
};
const limiter: rateLimit.Instance = new rateLimit(limiterOption);
// Protections against attack
const corsOptions: cors.CorsOptions = {
methods: ["GET", "POST", "PUT", "DELETE", "PATCH"],
allowedHeaders: ["Content-Type", "x-access-token"]
};
app.use(cors(corsOptions));
app.use(helmet());
app.use(compression());
app.use(limiter);
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
if (process.env.DEBUG === 'true')
app.use(logger(process.env.NODE_ENV));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
//Routes declaration
require('./routes/routes')(app);
module.exports = app;