-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (43 loc) · 1.18 KB
/
index.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 connection = require('./lib/connection');
const express = require('express');
const session = require('express-session');
const MySQLStore = require('express-mysql-session');
const bodyParser = require('body-parser');
const cors = require('./node_modules/cors');
const HOUR = 1000 * 60 * 60
const app = express();
app.use(cors({
origin: function (origin, callback) {
return callback(null, true);
},
optionsSuccessStatus: 200,
credentials: true
}));
const storeOptions = {
clearExpired: true
}
const sessionStore = new MySQLStore(storeOptions, connection);
const {
PORT = 8000,
SESSION_AGE = HOUR * 24,
SESSION_NAME = 'sid',
SESSION_SECRET = 'this is a secret, shhh'
} = process.env
app.use(session({
name: SESSION_NAME,
resave: false,
saveUninitialized: false,
secret: SESSION_SECRET,
store: sessionStore,
cookie: {
maxAge: SESSION_AGE,
sameSite: true
}
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({ type: 'applicationlication/json' }));
require("./routes/app.routes")(app);
app.listen(PORT, () => console.log(
`App Running on ${PORT}`
));