-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
85 lines (71 loc) · 1.89 KB
/
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
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
var DatabaseHelper = require("./core/DatabaseHelper")
var express = require('express');
var app = express();
var router = express.Router()
var path = __dirname + "/views/";
var bodyParser = require("body-parser")
var flash = require("connect-flash")
var passport = require("passport")
var session = require("express-session")
var questionController = require("./api/controllers/ChallengeController")
var sessionSecret = {
secret: 'apsc',
resave: true,
saveUninitialized: true,
cookie: {
secure: false
}
}
require("./core/passport")
require("./api/models/User")
//to accept form values
app.use(bodyParser.urlencoded({
extended: false
}))
app.use(bodyParser.json())
app.use(session(sessionSecret))
//connect-flash
app.use(flash())
//to use passport and session
app.use(passport.initialize())
app.use(passport.session())
//to use static files
app.use(express.static(__dirname + '/node_modules/bootstrap/dist'));
app.use(express.static(__dirname + "/public/"));
//set the template engine
app.set('view engine', 'pug')
app.set('views', './views')
router.use('/api', require("./api/routes"))
router.use((req, res, next) => {
next();
});
router.get("/", (req, res) => {
if(!req.isAuthenticated())
res.render("index",{pageName:"loginPage"})
else
res.redirect("/dashboard")
});
router.get("/dashboard", (req, res) => {
if(!req.isAuthenticated())
res.redirect("/")
else
questionController.getQuestionTitles(req,res)
})
router.get("/challenge/:id",(req,res) => {
// if(!req.isAuthenticated())
// res.redirect("/")
// else
questionController.getQuestion(req.params.id , res);
})
router.get("/logout",(req,res)=>{
req.logout();
console.log("USer Logged In",req.isAuthenticated())
res.render("index",{pageName:"loginPage"})
})
app.use("/", router);
app.use("*", function (req, res) {
res.render("404");
});
app.listen(80, function () {
console.log("Live at Port 3000");
});