-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (43 loc) · 1.23 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
require("dotenv").config()
const express = require("express")
const cookieParser = require("cookie-parser")
const authRouter = require("./routes/auth.router")
const blogRouter = require("./routes/blog.router")
const writerRouter = require("./routes/writer.router")
const authenticate = require("./auth")
const app = express()
app.set("view engine", "ejs")
app.set("views", "./views")
app.use(express.urlencoded({extended: false}))
app.use(express.static(__dirname + "/public"))
app.use(express.static(__dirname + "/node_modules/bootstrap/dist"))
app.use(cookieParser())
// EJS Views
app.get("/", (req, res) => {
res.render("home")
})
app.get("/signup", (req, res) => {
res.render("signup")
})
app.get("/signin", (req, res) => {
res.render("signin")
})
// API Routes
app.use("/auth", authRouter)
app.use("/blog", blogRouter)
app.use("/writer", authenticate, writerRouter)
// Handle unknown routes
app.use((req, res, next) => {
res.status(404).send({
message: "Sorry, the route you requested does not exist!"
})
next()
})
// Error handler
app.use((err, req, res, next) => {
res.status(err.status || 500).send({
message: "An error occured. Oops!",
error: err.toString()
})
})
module.exports = app