-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
44 lines (43 loc) · 1.37 KB
/
server.js
File metadata and controls
44 lines (43 loc) · 1.37 KB
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
const http = require('http');
const fs = require('fs');
http.createServer((req, res) => {
if(req.url === '/') {
return fs.readFile('./main.html', (err, data) => {
if(err) throw err;
res.end(data);
});
} else if(req.url.startsWith('/time/')) {
const sp = req.url.split('/');
if(req.url == '/time/') {
return fs.readFile('404.html', (err, data) => {
if(err) throw err;
res.end(data);
});
} else if(sp.length < 5) {
let q = '';
let loopcount = 5 - sp.length;
for(let i=0; i<loopcount; i++)
q += '/0';
return res.end(`<script type="text/javascript">location.href+="${q}";</script>`);
} else if (sp.length === 5 || (sp.length == 6 && sp[5] == '')) {
return fs.readFile('./time.html', (err, data) => {
if(err) throw err;
res.end(data);
});
} return fs.readFile('404.html', (err, data) => {
if(err) throw err;
res.end(data);
});
} else if(req.url.startsWith('/query?') && req.url.split('?').length === 2) {
const query = req.url.split('?')[1].split('&');
let q = '/time';
for(let i=0; i<query.length; i++)
q += '/' + query[i].split('=')[1];
return res.end(`<script type="text/javascript">location.href="${q}";</script>`);
} return fs.readFile('404.html', (err, data) => {
if(err) throw err;
res.end(data);
});
}).listen(80, () => {
console.log('Server Running At Port 80');
});