This commit is contained in:
backuppc
2026-01-21 13:07:18 +09:00
parent d63590620f
commit 4afbb1c299

View File

@@ -99,14 +99,17 @@ function startServer() {
}
}
// Fix for Windows: req.url starts with / which path.join treats as absolute
const requestPath = req.url === '/' ? '/index.html' : req.url;
// Fix for Windows & Query Strings
// Parse URL to get pathname (ignore query strings)
const parsedUrl = new URL(req.url, `http://${req.headers.host || 'localhost'}`);
let requestPath = parsedUrl.pathname;
if (requestPath === '/') requestPath = '/index.html';
// Remove leading slash for path.join to work relatively
const relativePath = requestPath.startsWith('/') ? requestPath.slice(1) : requestPath;
// Decoding URL (handling spaces etc)
const decodedPath = decodeURIComponent(relativePath);
let filePath = path.join(__dirname, 'dist', decodedPath);
// Prevent directory traversal