Fix the example code for correct and incorrect error handling in the documentation.

This commit is contained in:
Dorian Niemiec 2024-08-27 08:10:12 +02:00
parent 420f135b22
commit 923e7eebcb

View file

@ -1436,7 +1436,7 @@ if(href == "/page.svr") {
var id = uobject.query.id;
if(!id) id = "index";
if(fs.existsSync("pages/" + id + ".html")) {
fs.readFile("pages/" + id + ".html", function(err2, data2)) {
fs.readFile("pages/" + id + ".html", function(err2, data2) {
if(err2) throw err2; //EVIL TWO!!!
res.writeHead(200,"OK", headers);
res.end(data.toString().replace("{websiteContents}",data2.toString()));
@ -1477,9 +1477,9 @@ if(href == "/page.svr") {
}
var id = uobject.query.id;
if(!id) id = "index";
id = id.replace(/\\/g,"/").replace(/(?:\/|^)\.\.(?=(\/|$))/g,"$1").replace(/\/+/g,"/") //Poor mans path sanitiation
id = id.replace(/\\/g,"/").replace(/(?:\/|^)\.\.(?=(\/|$))/g,"$1").replace(/\/+/g,"/"); //Poor mans path sanitiation
if(fs.existsSync("pages/" + id + ".html")) {
fs.readFile("pages/" + id + ".html", function(err2, data2)) {
fs.readFile("pages/" + id + ".html", function(err2, data2) {
if(err2) {
callServerError(500,err2);
return;