-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (61 loc) · 1.88 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
60
61
62
63
64
65
66
67
68
69
70
71
72
// environment variables
require("dotenv").config();
const {
REDIS_URL,
SESSION_NAME,
SESSION_SECRET,
SESSION_DURATION,
PORT
} = process.env
// SERVER SETTINGS
const express = require('express');
const session = require("express-session");
const redis = require("redis");
const redisClient = redis.createClient(REDIS_URL)
const RedisStore = require("connect-redis")(session)
const path = require('path');
const app = express();
const favicon = require("serve-favicon");
const fileUpload = require("express-fileupload");
const helmet = require("helmet");
const noCache = require("nocache")
// TODO: add compression
// TODO: add rate limiter
// SERVER CONFIGURATION
app.use(helmet.hidePoweredBy());
app.use(helmet.noSniff());
app.use(helmet.xssFilter());
app.use(noCache())
app.set("view engine", "ejs");
app.set('views', './View');
app.use('/static',express.static(path.join(__dirname, 'static')));
app.disable('x-powered-by');
app.use(express.json());
app.use(express.urlencoded({extended : true}));
app.use(favicon(path.join(__dirname, "static", "assets", "favicon.png")))
app.use(fileUpload())
// MIDDLEWARES
require("./_Database") // database connection
app.use(session({
name : SESSION_NAME,
secret : SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie : {
httpOnly: true,
maxAge : parseInt(SESSION_DURATION),
sameSite : true,
},
// store
store : new RedisStore({
client: redisClient,
url : REDIS_URL ?? null
})
}))
// ROUTE MIDDLEWARES
app.use('/', require('./_Routes/accountRoutes'))
app.use('/moovey/list', require('./_Routes/listRoutes'))
app.use('/moovey', require('./_Routes/blogRoutes'))
app.use('/dashboard', require('./_Routes/dashboardRoutes'))
app.get('*', (req, res) => res.render("pages/404", {title : 'Page Not Found'}))
app.listen(PORT, ()=> console.log(`Server running on port ${PORT}`));