-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
128 lines (102 loc) · 3.04 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const session = require("express-session");
const flash = require("connect-flash");
const passport = require("passport");
const Category = require("./models/Category");
const app = express();
const passportConfig = require("./config/passport");
passportConfig(passport);
const { ensureAuthenticated } = require("./config/auth");
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(
session({
secret: "secret",
resave: true,
saveUninitialized: true,
})
);
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
mongoose.connect("mongodb://localhost:27017/testDB", {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
});
app.use(function (req, res, next) {
res.locals.success_msg = req.flash("success_msg");
res.locals.error_msg = req.flash("error_msg");
res.locals.error = req.flash("error");
res.locals.login = req.isAuthenticated();
next();
});
app.use(function (req, res, next) {
// console.log(req.user);
if (req.isAuthenticated()) {
res.locals.admin = req.user.isAdmin;
res.locals.user = req.user;
}
next();
});
const indexRouter = require("./routes/home");
app.use("/", indexRouter);
const adminRouter = require("./routes/admin");
app.use("/admin", adminRouter);
const questionRouter = require("./routes/question");
app.use("/question", questionRouter);
const privateSpaceRouter = require("./routes/privatespace");
app.use("/privatespace", privateSpaceRouter);
// app.get("/", (req, res) => {
// res.render("home", {
// questions: questions,
// user: user,
// category: "Technology",
// });
// });
// app.get("/login", (req, res) => {
// res.render("login");
// });
// app.get("/register", (req, res) => {
// res.render("register");
// });
// app.get("/about", (req, res) => {
// res.render("about", { user: user });
// });
// app.get("/question/:id", (req, res) => {
// const reqId = req.params.id;
// var question;
// questions.forEach((ques) => {
// if (ques.id == reqId) {
// question = ques;
// }
// });
// res.render("question", { question: question, title: null });
// });
// app.post("/", (req, res) => {
// console.log(req.body);
// });
// app.get("/comments", (req, res) => {
// res.render("comments");
// });
// app.get("/askquestion", async (req, res) => {
// const categories = await Category.find({});
// res.render("askques", { categories: categories, title: "Post Question" });
// });
// app.get("/answer/:id", (req, res) => {
// var reqId = req.params.id;
// var question;
// questions.forEach((ques) => {
// if (ques.id == reqId) {
// question = ques;
// }
// });
// res.render("answer", { question: question, title: "Answer Page" });
// });
// app.get("/question/report/:id", (req, res) => {
// res.render("report", { title: "Report" });
// });
app.listen(3000, () => console.log("Server is up and running on port 3000."));