..
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user