-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (46 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
57
const cors = require('cors');
const express = require('express');
const passport = require('passport');
require('@controllers/passportController');
const session = require('express-session');
const corsOptions = require('./utils/corsConfig');
require('dotenv').config();
const app = express();
app.use(cors(corsOptions));
app.use(require('morgan')('combined'));
app.use(require('helmet')());
app.use(require('@utils/cspConfig'));
app.use(
session({
secret: process.env.SESSION_SECRET,
resave: true,
saveUninitialized: true,
cookie: {
secure: process.env.NODE_ENV === 'production', // Set to true in production for HTTPS
maxAge: 86400000, // 1 day
},
})
);
app.use(passport.initialize());
app.use(passport.session());
// ways to submit data to the server
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// routers
const authRouter = require('@routers/authRouter');
const usersRouter = require('@routers/usersRouter');
const adminRouter = require('@routers/adminRouter');
const apiRouter = require('@routers/apiRouter');
// using the routers
app.use('/auth', authRouter);
app.use('/users', usersRouter);
app.use('/admin', adminRouter);
app.use('/api', apiRouter);
app.use((err, req, res) => {
if (err) {
console.error(err.stack);
return res.status(500).end();
}
res.status(404);
});
module.exports = app;