diff --git a/run.js b/run.js index 79f758d..9986384 100644 --- a/run.js +++ b/run.js @@ -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("
internal error"+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("internal error"+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("internal error"+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); }); diff --git a/templates/404.html b/templates/404.html new file mode 100644 index 0000000..1b7afc7 --- /dev/null +++ b/templates/404.html @@ -0,0 +1,10 @@ + + +