-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (46 loc) · 1.32 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
53
54
55
56
57
58
59
const express = require("express");
const app = express();
const port = process.env.PORT || 3000;
const host = "0.0.0.0";
const multer = require('multer')
const passport = require('passport')
const session = require('express-session')
const SequelizeStore = require('connect-session-sequelize')(session.Store)
const path = require("path");
const layouts = require("express-ejs-layouts");
const db = require('./db/helpers/init')
// Session store
const sessionStore = new SequelizeStore({
db: db,
})
// Parse JSON requests
app.use(express.json())
app.use(multer().none())
const cookieParser = require('cookie-parser')
app.use(express.urlencoded({ extended: false }));
// Templates
app.use(layouts);
app.set("views", path.join(__dirname, "app/views"));
app.set("layout", "layouts/application");
app.set("view engine", "ejs");
// Static files
app.use(express.static(__dirname + '/public'))
// Sessions
app.use(
session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
store: sessionStore,
cookie: {
maxAge: 1000 * 60 * 60 * 24 * 7, // 1 week
},
})
)
sessionStore.sync()
app.use(passport.authenticate('session'))
// Routes
app.use("/", require("./config/routes"));
app.listen(port, host, () => {
console.log(`Example app listening on http://${host}:${port}`);
});