-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
77 lines (61 loc) · 1.78 KB
/
server.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require("dotenv").config()
const express = require('express');
const app = express();
const nunjucks = require('nunjucks');
const log = require('./handlers/logger');
const db = require('./handlers/db');
const path = require("path")
const passport = require('passport');
const loadPassport = require("./handlers/passport");
const session = require("express-session")
const SequelizeStore = require("connect-session-sequelize")(session.Store);
const bodyParser = require('body-parser');
const flash = require('connect-flash');
const { rateLimit } = require('express-rate-limit');
const { checkSetup } = require("./handlers/checkAuth");
app.use(bodyParser.urlencoded({ extended: false }));
loadPassport(passport)
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true,
secure: false
},
store: new SequelizeStore({
db: db
})
}))
app.use(passport.initialize());
app.use(passport.session());
// FLASH MESSAGES
app.use(flash())
// RATE LIMIT
app.use(rateLimit({
windowMs: 5 * 60 * 1000,
max: 250
}));
app.use("/", express.static(path.join(__dirname, "public")))
app.set('view engine', 'njk');
try {
db.sync()
db.authenticate()
log.success("Database is connected successfully")
} catch (err) {
log.error("Error connecting to database: " + err)
}
nunjucks.configure('views', {
autoescape: true,
express: app,
watch: true
});
app.use("/dash", require("./routes/index").home);
app.use("/setup", require("./routes/index").setup)
app.use(checkSetup);
app.use("/auth", require("./routes/auth"));
app.use("/admin", require("./routes/admin"));
app.use("/api", require("./routes/api"));
app.listen(8000, () => {
log.success("Server is listening on port 8000")
})