-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
72 lines (63 loc) · 1.9 KB
/
main.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
// -------- DEPENDENCIES --------
const dotEnv = require("dotenv").config();
const envConfig = require("./envConfig");
const compression = require("compression")
const express = require("express");
const cors = require("cors");
const session = require("express-session");
const MemoryStore = require('memorystore')(session);
const schedule =require('node-schedule');
const bookingNotifier = require("./services/functions/bookingNotifier")
// ------- SERVER SCHEDULER --------
const rule = new schedule.RecurrenceRule();
rule.hour = 0
rule.minute = 5
const job = schedule.scheduleJob(rule, function(){
bookingNotifier()
})
// -------- DEFINITIONS -------
const app = express();
const currentYear = new Date().getFullYear();
// -------- MAIN MIDDLEWARES --------
app.use(compression());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(
session({
store: new MemoryStore({ checkPeriod: 86400000 }),
secret: envConfig.session_secret,
resave: true,
saveUninitialized: true,
cookie: {
path: "/",
// secure: true,
sameSite: true,
},
})
);
app.use(express.static("public"));
app.use(cors());
// -------- TEMPLATE GENERATOR --------
app.set("view engine", "ejs");
app.set("views", "./ejs/views");
// -------- ROUTERS ---------
const mainRouter = require("./routers/mainRouter");
const salesRouter = require("./routers/salesRouter");
const distRouter = require("./routers/distRouter");
// ------- ROUTES --------
app.use("/", mainRouter);
app.use("/sales", salesRouter);
app.use("/dist", distRouter);
app.get('*', (req, res) => {
return res.status(404).render('error', {
pageTitle: "Nope!",
date: currentYear,
message: `This one does not exist!`,
})
})
// -------- SERVER LISTEN --------
const server = app.listen(envConfig.port, envConfig.host, () =>
console.log(
`Server ready and listening on http://${envConfig.host}:${envConfig.port}`
)
);