-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxford.js
98 lines (86 loc) · 2.34 KB
/
noxford.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// loading environment
require('dotenv').config();
// modules
const express = require("express");
const layouts = require("express-ejs-layouts");
const session = require("express-session");
// routers
const _home_ = require("./routes/_home_.js");
const _login_ = require("./routes/_login_.js");
const _registration_ = require("./routes/_registration_.js");
const _collection_ = require("./routes/_collection_.js");
const _books_ = require("./routes/_books_.js");
const _place_ = require("./routes/_place_.js");
const _account_ = require("./routes/_account_.js");
const _search_ = require("./routes/_search_.js");
// app
const app = express();
const port = process.env.PORT || 3000;
// app configurting
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(layouts);
app.use(express.urlencoded({ limit: '10mb', extended: false }));
app.use(session({
secret: "user login status",
resave: false,
saveUninitialized: false,
cookie: {userId: null}
}));
app.use(function(req, res, next) {
res.locals.userId = req.session.userId;
next();
});
// ***** routing *****
// homepage
app.use("/", _home_);
// collection
app.use("/collection", _collection_);
// books page
app.use("/books", _books_);
// place hold page
app.use("/place", _place_);
// getcard
app.get("/getcard", (req, res) => {
res.render("pages/getcard", {title: "Get a card"});
});
// search
app.use("/search", _search_);
// account page
app.use("/account", _account_);
// login
app.use("/login", _login_);
// logout
app.use("/logout", (req, res) => {
req.session.userId = null;
res.redirect("/");
});
// register
app.use("/register", _registration_);
// donate get
app.get("/donate", (req, res) => {
res.render("pages/donate", {title: "Donate"});
});
// donate post
app.post("/donate", (req, res) => {
res.render("pages/donate", {
title: "Donate",
flash: "Cannot Donate: No donation system available",
type: "warning"
});
});
// others page
app.get("/others", (req, res) => {
res.render("pages/others", {title: "Others"});
});
// about page
app.get("/about", (req, res) => {
res.render("pages/about", {title: "About"});
});
// 404 Error Page
app.get("*", (req, res) => {
res.status(400).render("misc/notFound", {title: "404 Not Found"});
});
// listening
app.listen(port);
console.log("Noxford Library Started Successfully!");