Skip to content

Commit 8c0b587

Browse files
authored
Merge pull request #4 from J-P-S-O/master
never gonna give you up
2 parents 876b29e + 114a1b3 commit 8c0b587

3 files changed

Lines changed: 56 additions & 5 deletions

File tree

run.js

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,53 @@ const requestListener = function (req, res) {
2828
if (req.url === "/test"){
2929
fs.readFile("templates/rick.html", function (err,data) {
3030
if (err) {
31-
res.writeHead(404);
32-
res.end(JSON.stringify(err));
31+
res.writeHead(203);
32+
res.end("<html><body><b>internal error</b></body></html>"+JSON.stringify(err));
3333
return;
3434
}
3535
res.writeHead(200);
3636
res.end(data);
3737
});
3838
}else if (req.url === "/"){
39-
40-
}else {
39+
//template stuff
40+
res.writeHead(200)
41+
res.end("N/A")
42+
}else if(req.url.includes("/../")) {
43+
fs.readFile("templates/500.html", function (err,data) {
44+
if (err) {
45+
res.writeHead(203);
46+
res.end("<html><body><b>internal error</b></body></html>"+JSON.stringify(err));
47+
return;
48+
}
49+
res.writeHead(200);
50+
res.end(data);
51+
});
52+
53+
} else {
4154
fs.readFile("static" + req.url, function (err,data) {
4255
if (err) {
43-
res.writeHead(404);
56+
57+
if(err.code=="ENOENT"){
58+
59+
fs.readFile("templates/404.html", function (err,data) {
60+
if (err) {
61+
res.writeHead(203);
62+
res.end("<html><body><b>internal error</b></body></html>"+JSON.stringify(err));
63+
return;
64+
}
65+
66+
res.writeHead(404);
67+
res.end(data);
68+
return;
69+
})
70+
return;
71+
}
72+
73+
res.writeHead(203);
4474
res.end(JSON.stringify(err));
4575
return;
4676
}
77+
4778
res.writeHead(200);
4879
res.end(data);
4980
});

templates/404.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html>
2+
<body>
3+
<h1>
4+
404.
5+
</h1>
6+
<h2>
7+
<i>Unexisting things cannot be found</i>
8+
</h2>
9+
</body>
10+
</html>

templates/500.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html>
2+
<body>
3+
<h1>
4+
500
5+
</h1>
6+
<h2>
7+
You asked for something dangerous
8+
</h2>
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)