-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (39 loc) · 1.36 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
import 'dotenv/config';
import express from 'express';
import path from 'path';
import helmet from 'helmet';
import compression from 'compression';
import morgan from 'morgan';
import bodyParser from 'body-parser';
import passport from 'passport';
import './config/db';
import './config/passport';
import session from './config/sessionConfig';
import authenticationMiddleware from './middleware/authenticationMiddleware';
import routeValidators from './routes/routeValidators';
import checkValidationErrors from './middleware/checkValidationErrors';
import routeControllers from './routes/routeControllers';
import errorHandler from './middleware/errorHandler';
import cors from 'cors';
import logger from './config/logger';
const app = express();
const port = process.env.PORT || '3000';
app.use(cors({
origin: true,
credentials: true
}));
app.use(helmet());
app.use(compression());
app.use(morgan(process.env.NODE_ENV === 'production' ? 'combined' : 'dev'));
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(session);
app.use(passport.initialize());
app.use(passport.session());
app.use(authenticationMiddleware);
app.use(routeValidators);
app.use(checkValidationErrors);
app.use(routeControllers);
app.use(errorHandler);
app.listen(port, () => logger.info(`app running on port ${port}`));