-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes_pages.js
executable file
·40 lines (37 loc) · 1.07 KB
/
routes_pages.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
module.exports = function(app) {
/*
We can use a regular expression (regex) for our route
so in this case it will match both "map" and "map.html".
Since this comes *before* the public folder, this means
that no user will be able to load map.html without
being logged in.
*/
app.get('/maze(.html)?', function(req,res) {
//Check if the user is logged in
if (!req.session.user) {
res.redirect("/login");
return;
}
//send forward map.html
res.sendFile(__dirname + "/public/maze.html");
});
app.get('/mazeChoice(.html)?', function(req,res) {
//Check if the user is logged in
if (!req.session.user) {
res.redirect("/login");
return;
}
//send forward map.html
res.sendFile(__dirname + "/public/mazeChoice.html");
});
/*
This is just a way of sending login.html to the user
when they visit localhost:8000/login
*/
app.get('/login', function(req, res){
// sendFile requires an absolute path, so we
// have to use the __dirname, which tells us
// what directory we are running node in.
res.sendFile(__dirname + "/public/index.html");
});
};