-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (34 loc) · 1.93 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
const express = require("express");
const expressLayouts = require("express-ejs-layouts");
const pageController = require("./controllers/pageController");
const userController = require("./controllers/userController");
const questionController = require("./controllers/questionController");
const middleWares = require("./controllers/middleWares");
require("dotenv").config();
const cookieParser = require("cookie-parser");
const app = express();
const port = process.env.PORT;
app.set("view engine", "ejs");
app.use(expressLayouts);
app.set("layout", "layouts/mainLayout");
app.use(express.static('public'));
app.use("/css", express.static(__dirname + "public/css"));
app.use("/scripts", express.static(__dirname + "public/scripts"));
app.use(express.json());
app.use(express.urlencoded());
app.use(cookieParser());
app.get("/", middleWares.alReadyLoggedIn, pageController.indexpage);
app.get("/registerpage", middleWares.alReadyLoggedIn, pageController.registerpage);
app.post("/register", userController.register);
app.get("/loginpage", middleWares.alReadyLoggedIn, pageController.loginpage);
app.post("/login", userController.login);
app.get("/homepage", middleWares.isLoggedIn, pageController.homepage);
app.post("/questions", middleWares.isLoggedIn, questionController.sendQuestions);
app.get("/questionspage", middleWares.isLoggedIn, middleWares.isAdmin, pageController.questionpage);
app.get("/userspage", middleWares.isLoggedIn, middleWares.isAdmin, pageController.userspage);
app.post("/addUpdateQuestion", middleWares.isLoggedIn, middleWares.isAdmin, questionController.addUpdateQuestion);
app.delete("/deleteQuestion", middleWares.isLoggedIn, middleWares.isAdmin, questionController.deleteQuestion);
app.put("/updateuserrole", middleWares.isLoggedIn, middleWares.isAdmin, userController.updateUserRole);
app.get("/logout", userController.logout);
app.get("/*", pageController.errorpage);
app.listen(port, ()=>{console.log(`App started on port : ${port}`);})