forked from cmda-minor-web-cases/so-nuts-2122
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
64 lines (55 loc) · 1.99 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
// Import Dotenv.
require("dotenv").config()
// Import Express.
const express = require("express")
// Import Handlebars.
const handlebars = require("express-handlebars")
// Import compression.
const compression = require("compression")
// Import routes.
const login = require("./routes/login.js")
const onboarding = require("./routes/onboarding.js")
const questionnaire = require("./routes/questionnaire.js")
const goals = require("./routes/goals.js")
const increase_streak = require("./routes/increase_streak.js")
const delete_user_goal = require("./routes/delete_user_goal.js")
const add_goals = require("./routes/add_goals.js")
const profile = require("./routes/profile.js")
const offline = require("./routes/offline.js")
// Initialise Express.
express()
// Compress all responses.
.use(compression())
// Cache non-HTML GET requests for one year (see https://ashton.codes/set-cache-control-max-age-1-year/).
.use((req, res, next) => {
if (req.method == "GET" && !(req.rawHeaders.toString().includes("text/html"))) {
res.set("Cache-control", "public, max-age=31536000")
}
// Pass on the request.
next()
})
// Render static files.
.use(express.static("static"))
// Set the view engine to Handlebars and import the helpers.
.engine("handlebars", handlebars.engine({
helpers: require("./helpers")
}))
.set("view engine", "handlebars")
// Parse incoming requests.
.use(express.urlencoded({
extended: true
}))
// Configure routes.
.use("/", login)
.use("/onboarding", onboarding)
.use("/questionnaire", questionnaire)
.use("/goals", goals)
.use("/increase_streak", increase_streak)
.use("/delete_user_goal", delete_user_goal)
.use("/add_goals", add_goals)
.use("/profile", profile)
.use("/offline", offline)
// Set and log the port for Express.
.listen(process.env.PORT, () => {
console.log(`Express running at http://localhost:${process.env.PORT}.`)
})