-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
56 lines (41 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
45
46
47
48
49
50
51
52
53
54
55
56
require('dotenv').config();
const cookieParser = require('cookie-parser');
const cors = require('cors');
const express = require('express');
const helmet = require('helmet');
const createError = require('http-errors');
//const Redis = require('ioredis');
const msal = require('./lib/msal');
const passport = require('./lib/passport');
const app = express();
app.set('trust proxy', process.env.CURRENT_ENV !== 'dev' ? 1 : false);
app.use(cors({
'origin': process.env.TRUSTED_DOMAIN,
'methods': ['GET', 'HEAD', 'POST'],
'credentials': true,
'optionsSuccessStatus': 200
}));
app.use(helmet());
/*const redisClient = new Redis({
port: process.env.REDIS_PORT,
host: process.env.REDIS_HOST,
username: process.env.REDIS_USER,
password: process.env.REDIS_PASS
});*/
app.use(cookieParser());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
msal.initialise(app);
passport.initialise(app);
app.use('/', require('./router/indexRouter'));
app.use(function (req, res, next) {
next(createError(404, `Could not ${req.method} resource '${req.originalUrl}'`));
});
app.use(function (err, req, res, next) {
console.error(`[${new Date(Date.now()).toUTCString()}] - ${err.name}: ${err.message}`);
console.error(err.stack);
res.status(err.statusCode || 500).json({
error: err.message
});
});
module.exports = app;