From bb2ffbb79230e5f2e385f6c5ca53db5481f35376 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Tue, 14 Oct 2025 16:19:45 -0500 Subject: [PATCH] express 404 --- src/index.ts | 14 ++++++++------ src/webpage/404.html | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 239e333..887c7b0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -27,7 +27,7 @@ async function getDirectories(path: string): Promise { } let dirs: dirtype | undefined = undefined; -async function combinePath(path: string, tryAgain = true): Promise { +async function combinePath(path: string, tryAgain = true, reqpath: string): Promise { if (!dirs) { dirs = await getDirectories(__dirname); } @@ -48,18 +48,20 @@ async function combinePath(path: string, tryAgain = true): Promise { } if (find(pathDir, dirs)) { return __dirname + path; + } else if (reqpath.startsWith("/channels")) { + return __dirname + "/webpage/app.html"; } else { if (!path.includes(".")) { - const str = await combinePath(path + ".html", false); - if (str !== __dirname + "/webpage/app.html") { + const str = await combinePath(path + ".html", false, reqpath); + if (str !== __dirname + "/webpage/404.html") { return str; } } if (devmode && tryAgain) { dirs = await getDirectories(__dirname); - return combinePath(path, false); + return combinePath(path, false, reqpath); } - return __dirname + "/webpage/app.html"; + return __dirname + "/webpage/404.html"; } } interface Instance { @@ -184,7 +186,7 @@ app.use("/", async (req: Request, res: Response) => { res.sendFile(path.join(__dirname, "webpage", "app.html")); return; } - const filePath = await combinePath("/webpage/" + req.path); + const filePath = await combinePath("/webpage/" + req.path, true, req.path); res.sendFile(filePath); }); diff --git a/src/webpage/404.html b/src/webpage/404.html index 7081795..2ec8a3c 100644 --- a/src/webpage/404.html +++ b/src/webpage/404.html @@ -30,7 +30,7 @@
- +

It seems you're lost

404 Page Not Found