-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (51 loc) · 1.74 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
import express from "express"
import morgan from "morgan"
import bodyParser from "body-parser"
import cookieParser from "cookie-parser"
import helmet from "helmet"
import favicon from "serve-favicon"
import path from "path"
import { dirname } from "path"
import { fileURLToPath } from "url"
import mongoSanitize from "express-mongo-sanitize"
import { PORT } from "./config/app.js"
import "./config/database.js"
import simpleRoutes from "./controllers/simple-pages.js"
import shotsRoutes from "./controllers/shots.js"
import machinesRoutes from "./controllers/machines.js"
import grindersRoutes from "./controllers/grinders.js"
import beansRoutes from "./controllers/beans.js"
import usersRoutes from "./controllers/users.js"
import adminRoutes from "./controllers/admin.js"
import searchRoutes from "./controllers/search.js"
const __dirname = dirname(fileURLToPath(import.meta.url))
const app = express()
app.set("view engine", "ejs")
app.use("/assets", express.static(__dirname + "/public"))
app.use(favicon(path.join(__dirname, "public", "favicon.ico")))
app.use(express.urlencoded({ extended: true }))
if (process.env.NODE_ENV === "dev") {
app.use(morgan("tiny"))
}
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.use(cookieParser())
app.use(helmet())
app.use(
mongoSanitize({
onSanitize: ({ req, key }) => {
console.warn(`This request[${key}] is sanitized`, req)
},
})
)
app.use(simpleRoutes)
app.use("/shots", shotsRoutes)
app.use("/machines", machinesRoutes)
app.use("/grinders", grindersRoutes)
app.use("/beans", beansRoutes)
app.use("/users", usersRoutes)
app.use("/admin", adminRoutes)
app.use("/search", searchRoutes)
app.listen(PORT, () => {
console.log(`👋 Started espresso server on port ${PORT}`)
})