-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (25 loc) · 877 Bytes
/
index.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
const express = require("express")
const path = require('path')
const bodyParser = require("body-parser")
const booksRouter = require("./routers/books-router")
const loginRouter = require("./routers/login-router")
const mainRouter = require("./routers/main-router")
const borrowRouter = require('./routers/borrowed-router')
const app = express()
// make static directory to public
app.use(express.static(path.join(__dirname + "/public")))
// setting view engine
app.set("view engine","pug")
app.set("views",path.join(__dirname + "/views"))
// using bodyParser
app.use(bodyParser.urlencoded({extended: true}))
app.use(bodyParser.json())
// adding routers
app.use("/books",booksRouter)
app.use("/login",loginRouter)
app.use("/borrow",borrowRouter)
// !!redirecting for preventing 401 or 404 status
app.use("*",(req,res) => {
res.redirect('/login')
})
app.listen(80)