-
Notifications
You must be signed in to change notification settings - Fork 13
/
app.js
52 lines (42 loc) · 1.24 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
50
51
52
const express = require('express');
const helmet = require('helmet');
const mongoSanitize = require('express-mongo-sanitize');
const cors = require('cors');
const corsSetup = require('./conf/corsSetup');
const setupRoutes = require('./route-setup/routeSetup');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const path = require('path');
const { connect } = require('./conf/database');
require('dotenv').config({
path: `.env.${process.env.NODE_ENV}`
});
const app = express();
// Middleware
app.use(express.json({ limit: '50mb', extended: true }));
app.use(express.urlencoded({ limit: '50mb', extended: true, parameterLimit: 50000 }));
app.use(mongoSanitize({
allowDots: true,
replaceWith: '_',
}));
// Security
app.disable('x-powered-by');
app.use(helmet());
app.use(helmet.frameguard({ action: 'deny' }));
// Cross-origin resource sharing
app.use(cors('*'));
app.use(corsSetup);
// Logging
app.use(logger('combined'));
// Cookie parsing
app.use(cookieParser());
// Static files
app.use(express.static(path.join(__dirname, 'public')));
app.use('/assets', express.static('public'));
// View engine
app.set('view engine', 'ejs');
// Connect to database
connect();
// Setup routes
setupRoutes(app);
module.exports = app;