16
preview.ts
16
preview.ts
@@ -11,11 +11,17 @@ createServer((req, res) => {
|
|||||||
} else {
|
} else {
|
||||||
req_path = path.join(__dirname, "build", req.url);
|
req_path = path.join(__dirname, "build", req.url);
|
||||||
}
|
}
|
||||||
if (!existsSync(req_path)) {
|
let status_code = 200;
|
||||||
res.writeHead(404);
|
//req.url.includes("..")
|
||||||
//write file
|
if (!req_path.startsWith(path.join(__dirname, "build"))) {
|
||||||
res.write("404");
|
//nice try, bad request
|
||||||
|
res.writeHead(400);
|
||||||
|
res.write("400");
|
||||||
return res.end();
|
return res.end();
|
||||||
|
} else if (!existsSync(req_path)) {
|
||||||
|
status_code = 404;
|
||||||
|
//serve 404 page instead of non-existent page
|
||||||
|
req_path = path.join(__dirname, "build", "404.html");
|
||||||
}
|
}
|
||||||
//set content type
|
//set content type
|
||||||
let non_utf8_content_types: string[] = ["image/png", "image/gif", "image/jpeg", "video/mp4"];
|
let non_utf8_content_types: string[] = ["image/png", "image/gif", "image/jpeg", "video/mp4"];
|
||||||
@@ -49,7 +55,7 @@ createServer((req, res) => {
|
|||||||
default:
|
default:
|
||||||
content_type = "text/plain";
|
content_type = "text/plain";
|
||||||
}
|
}
|
||||||
res.writeHead(200, {
|
res.writeHead(status_code, {
|
||||||
"Content-Type": content_type,
|
"Content-Type": content_type,
|
||||||
});
|
});
|
||||||
//write file
|
//write file
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
<br>
|
<br>
|
||||||
<h2>prussiafan.club</h2>
|
<h2>prussiafan.club</h2>
|
||||||
<br>
|
<br>
|
||||||
<p>This is my blog. I also have a <a href="https://prussia.dev">portfolio</a>, <a href="https://prussia.dev/retro">retro style personal website</a>. I like free software, privacy, yada yada.</p>
|
<p>This is my blog. I also have a <a href="https://prussia.dev">portfolio</a>. Use Linux? Like Vim and i3/Sway? Then check out <a href="https://github.com/stjet/ming-wm">ming-wm</a>. I like free software, privacy, yada yada.</p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user