-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
59 lines (53 loc) · 1.46 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
require("dotenv").config()
const express = require("express")
const morgan = require("morgan")
const session = require("express-session")
const flash = require("connect-flash")
const bodyParser = require("body-parser")
const toursRouter = require("./routes/toursRouter")
const usersRouter = require("./routes/usersRouter")
const adminRouter = require("./routes/adminRouter")
const swaggerUi = require("swagger-ui-express")
const fs = require("fs")
const yaml = require("js-yaml")
const app = express()
app.use(bodyParser.urlencoded({ extended: true }))
app.set("views", __dirname + "/views")
app.set("view engine", "ejs")
// app.set("view engine", "ejs")
// app.set("views", "views")
// middleware dari express
// memodifikasi incoming body ke api kita
app.use(express.json())
app.use(morgan("dev"))
app.use(express.static(`${__dirname}/public`))
const swaggerDocument = yaml.load(
fs.readFileSync(
"./swagger/swagger.yaml",
"utf-8"
)
)
// swagger api
app.use(
"/api/docs",
swaggerUi.serve,
swaggerUi.setup(swaggerDocument)
)
// middleware logging
app.use((req, res, next) => {
req.requestTime = new Date().toString()
next()
})
// flash and express session for notification
app.use(
session({
secret: "geeksforgeeks",
saveUninitialized: true,
resave: true,
})
)
app.use(flash())
app.use("/api/v1/tours", toursRouter)
app.use("/api/v1/users", usersRouter)
app.use("/dashboard", adminRouter)
module.exports = app