-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (46 loc) · 1.48 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
const bodyParser = require('body-parser');
const express = require('express');
const session = require('express-session');
const app = express();
app.use(session({
secret: 'slim shady',
resave: false,
saveUninitialized: true
}))
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(__dirname + '/public'));
app.set('view engine', 'ejs');
const routeHome = require("./routes/home");
const routeLogin = require("./routes/login");
app.use("/home", routeHome);
app.use("/login", routeLogin);
app.get('/', function (request, response) {
if (request.session.userid) {
console.log("Session found: " + request.session.userid);
response.redirect("/home");
} else {
console.log("Session NOT found");
response.redirect("/login");
}
});
app.get('/logout', (request, response) => {
request.session.destroy();
response.redirect("/login");
});
app.get('/basic-table', function (request, response) {
console.log("showing tables");
response.redirect("basic-table");
});
app.get('*', function (request, response) {
// if (request.session.userid) {
// console.log("prohibited page; Session found for : " + request.session.userid);
// response.redirect("/") //goes back to home
// } else {
// console.log("prohibited page; Session NOT found for : " + request.session.userid);
// response.redirect("login");
// }
response.render("/login");
});
var server = app.listen(8038, function () {
console.log("app running and listening on port %s", server.address().port);
});