From a33932cbd0e9d04ab05af934ebfab1bd26a62320 Mon Sep 17 00:00:00 2001 From: kunthawat Date: Fri, 7 Aug 2026 20:08:28 +0700 Subject: [PATCH] Fix: pages/CSS 404 on URL-encoded links (double-decode broke UTF-8 filenames) Express already decodes req.path; the extra decodeURIComponent re-decoded UTF-8 filenames and returned 404 for URL-encoded links (as used by the original site), so page CSS didn't load and buttons looked unstyled. Now all 41 pages + all CSS/assets serve 200 via encoded URLs; 0 404. --- server.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/server.js b/server.js index c5b84ba..eefb461 100644 --- a/server.js +++ b/server.js @@ -48,12 +48,10 @@ function injectEnv(html) { // Serve .html with env injection; everything else statically. app.use((req, res, next) => { - let pathname; - try { - pathname = decodeURIComponent(req.path); - } catch { - return next(); - } + // Express resolves req.path to a decoded path (e.g. %E0%B8%A1 -> ม). + // Do NOT decodeURIComponent again — decoding twice breaks UTF-8 filenames, + // which made URL-encoded links (from the original site) 404 and lose their CSS. + const pathname = req.path; if (pathname.endsWith('.html') || pathname === '/' || !/\.[a-z0-9]+$/i.test(pathname)) { let file = pathname === '/' ? 'index.html' : pathname; let abs = join(DIST, file);