Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions run.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,53 @@ const requestListener = function (req, res) {
if (req.url === "/test"){
fs.readFile("templates/rick.html", function (err,data) {
if (err) {
res.writeHead(404);
res.end(JSON.stringify(err));
res.writeHead(203);
res.end("<html><body><b>internal error</b></body></html>"+JSON.stringify(err));
return;
}
res.writeHead(200);
res.end(data);
});
}else if (req.url === "/"){

}else {
//template stuff
res.writeHead(200)
res.end("N/A")
}else if(req.url.includes("/../")) {
fs.readFile("templates/500.html", function (err,data) {
if (err) {
res.writeHead(203);
res.end("<html><body><b>internal error</b></body></html>"+JSON.stringify(err));
return;
}
res.writeHead(200);
res.end(data);
});

} else {
fs.readFile("static" + req.url, function (err,data) {
if (err) {
res.writeHead(404);

if(err.code=="ENOENT"){

fs.readFile("templates/404.html", function (err,data) {
if (err) {
res.writeHead(203);
res.end("<html><body><b>internal error</b></body></html>"+JSON.stringify(err));
return;
}

res.writeHead(404);
res.end(data);
return;
})
return;
}

res.writeHead(203);
res.end(JSON.stringify(err));
return;
}

res.writeHead(200);
res.end(data);
});
Expand Down
10 changes: 10 additions & 0 deletions templates/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<body>
<h1>
404.
</h1>
<h2>
<i>Unexisting things cannot be found</i>
</h2>
</body>
</html>
10 changes: 10 additions & 0 deletions templates/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<body>
<h1>
500
</h1>
<h2>
You asked for something dangerous
</h2>
</body>
</html>