-
Notifications
You must be signed in to change notification settings - Fork 1
/
router copy.js
175 lines (134 loc) · 5 KB
/
router copy.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
const express = require("express");
const router = express.Router();
router.get('/', function(req, res){
// res.send(req.oidc.isAuthenticated() ? 'Logged in' : 'Logged out');
req.session.isAuth = true;
res.sendFile(__dirname + "/index.html");
});
router.get('/login', function(req, res){
res.sendFile(__dirname + "/login-page.html");
});
router.get('/signin', function(req, res){
res.sendFile(__dirname + "/signin.html");
});
router.get('/solar-system-explore', function(req, res){
res.sendFile(__dirname + "/solar.html");
});
router.get('/planets/:planet', function(req, res){
const requestedPlanet = req.params.planet;
if(isValidPlanet(requestedPlanet)){
return res.sendFile(__dirname + "/planets/" + requestedPlanet + ".html");
}
return res.send("<img src='https://http.cat/404'></img>");
});
function isValidPlanet(planetName) {
const validPlanets = ['mercury', 'venus', 'earth', 'mars', 'jupiter', 'saturn', 'uranus', 'neptune', 'sun', 'moon'];
return validPlanets.includes(planetName);
}
router.get('/blogs', function(req, res){
res.sendFile(__dirname + "/blogs.html");
});
const isAuth = (req, res, next) => {
if(req.session.isAuth){
next();
}
else{
res.redirect('/login');
}
}
router.get('/cosmic-blast', isAuth, function(req, res){
res.sendFile(__dirname + "/game.html");
});
router.get('/rockets', function(req, res){
res.sendFile(__dirname + "/rockets.html");
});
router.get('/about', function(req, res){
res.sendFile(__dirname + "/about.html");
});
router.get('/theory/:theories', function(req, res){
const requestedTheory = req.params.theories;
if(isValidTheory(requestedTheory)){
return res.sendFile(__dirname + "/theory/" + requestedTheory + ".html");
}
return res.send("<img src='https://http.cat/404'></img>");
});
function isValidTheory(theoryName) {
const validPlanets = ['big-bang', 'black-hole', 'parallel-universe', 'dark-matter', 'stars', 'galaxies'];
return validPlanets.includes(theoryName);
}
router.get('/missions/:mission', function(req, res){
const requestedMission = req.params.mission;
if(isValidMission(requestedMission)){
return res.sendFile(__dirname + "/missions/" + requestedMission + ".html");
}
return res.send("<img src='https://http.cat/404'></img><br><a href='/'><h3>Go to Home page</h3></a>");
});
function isValidMission(missionName) {
const validPlanets = ['mission-mars', 'chandrayaan-I', 'chandrayaan-II'];
return validPlanets.includes(missionName);
}
module.exports = router;
/* ==== Planets ==== */
/* router.get('/planets/:planet', function(req, res){
const requestedName = req.params.planet.toLowerCase(); // Lowercase for case-insensitive matching
// Check for valid planets
if (isValidPlanet(requestedName)) {
return res.sendFile(__dirname + "/" + requestedName + ".html");
}
res.end();
}); */
// Check for files with .css or .js extension
/* const extensionMatch = requestedName.match(/\.(css|js)$/i); // Regex for case-insensitive match
if (extensionMatch) {
return res.sendFile(__dirname + "/" + requestedName); // Send file without adding .html
}
return res.status(404).send("<img src='https://http.cat/404'></img>"); */
/* router.get('/planets/earth', function(req, res){
res.sendFile(__dirname + "/planets/earth.html");
});
router.get('/planets/mercury', function(req, res){
res.sendFile(__dirname + "/planets/mercury.html");
});
router.get('/planets/venus', function(req, res){
res.sendFile(__dirname + "/planets/venus.html");
});
router.get('/planets/mars', function(req, res){
res.sendFile(__dirname + "/planets/mars.html");
});
router.get('/planets/saturn', function(req, res){
res.sendFile(__dirname + "/planets/saturn.html");
});
router.get('/planets/jupiter', function(req, res){
res.sendFile(__dirname + "/planets/jupiter.html");
});
router.get('/planets/neptune', function(req, res){
res.sendFile(__dirname + "/planets/neptune.html");
});
router.get('/planets/uranus', function(req, res){
res.sendFile(__dirname + "/planets/uranus.html");
});
router.get('/planets/sun', function(req, res){
res.sendFile(__dirname + "/planets/sun.html");
});
router.get('/planets/moon', function(req, res){
res.sendFile(__dirname + "/planets/moon.html");
}); */
/* ==== THEORIES ==== */
/* router.get('/theory/big-bang', function(req, res){
res.sendFile(__dirname + "/theory/big-bang.html");
});
router.get('/theory/black-hole', function(req, res){
res.sendFile(__dirname + "/theory/black-hole.html");
});
router.get('/theory/parallel-universe', function(req, res){
res.sendFile(__dirname + "/theory/parallel-universe.html");
});
router.get('/theory/dark-matter', function(req, res){
res.sendFile(__dirname + "/theory/dark-matter.html");
});
router.get('/theory/stars-theory', function(req, res){
res.sendFile(__dirname + "/theory/stars.html");
});
router.get('/theory/galaxies', function(req, res){
res.sendFile(__dirname + "/theory/galaxies.html");
}); */