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.
This commit is contained in:
10
server.js
10
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);
|
||||
|
||||
Reference in New Issue
Block a user