-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
70 lines (59 loc) · 2.33 KB
/
app.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
const express = require("express")
const bodyParser = require("body-parser")
const boolParser = require("express-query-boolean")
const path = require("path")
const favicon = require("serve-favicon")
const hbs = require("hbs")
const passport = require("passport")
const hbsutils = require("hbs-utils")(hbs)
const morgan = require("morgan")
const sslRedirect = require("heroku-ssl-redirect").default
const ideahacks = require("./ideahacks")
const app = express()
// HTTPS Redirect
app.use(sslRedirect(["production"], 301))
// Logging
app.use(morgan("dev"))
// View and Asset Handling
app.set("port", process.env.PORT || 3000)
app.set("view engine", "hbs")
hbs.registerHelper("if_even", function (conditional, options) {
if (conditional % 2 === 0) {
return options.fn(this)
} else {
return options.inverse(this)
}
})
hbs.registerPartial("navbar", path.join(__dirname, "/views/partials/navbar.hbs"))
hbs.registerPartial("footer", path.join(__dirname, "/views/partials/footer.hbs"))
hbs.registerPartial("applicationModal", path.join(__dirname, "/views/partials/applicationModal.hbs"))
hbs.registerPartial("dashboardPartsModal", path.join(__dirname, "/views/partials/dashboardPartsModal.hbs"))
hbs.registerPartial("filter", path.join(__dirname, "/views/partials/filter.hbs"))
hbs.registerPartial("teamCreationModal", path.join(__dirname, "/views/partials/teamCreationModal.hbs"))
hbsutils.registerWatchedPartials(path.join(__dirname, "/views/partials"))
app.use(favicon(path.join(__dirname, "public", "favicon.ico")))
app.use(express.static(path.join(__dirname, "views")))
app.use(express.static(path.join(__dirname, "public")))
// Body Parsing (for parsing HTTP Requests)
app.use(bodyParser.json())
app.use(boolParser())
app.use(bodyParser.urlencoded({ extended: true }))
// Session handling
app.use(ideahacks.session)
app.use(passport.initialize())
app.use(passport.session())
// Routes
app.use(ideahacks.routes.mainRouter)
app.use("/admin", ideahacks.routes.adminRouter)
app.use("/dashboard", ideahacks.routes.dashboardRouter)
app.use(ideahacks.routes.partsRouter)
app.use(ideahacks.routes.teamRouter)
app.use(ideahacks.routes.userRouter)
app.use((req, res) => {
res.status(404).render("error", { status: res.statusCode })
})
app.use((err, req, res, next) => {
if (err) console.log(err)
res.status(500).render("error", { status: res.statusCode })
})
module.exports = app