fix(servertools): Fix wildcard path extraction for static/proxy handlers, correct serviceworker route, add local settings and test typo fix

This commit is contained in:
2025-09-03 12:33:04 +00:00
parent 0f22c91499
commit 776d6fb95d
7 changed files with 62 additions and 5 deletions

View File

@@ -36,7 +36,31 @@ export class HandlerStatic extends Handler {
}
// lets compute some paths
let filePath: string = requestPath.slice(req.route.path.length - 1); // lets slice of the root
// Extract the path using Express 5's params or fallback methods
let filePath: string;
if (req.params && req.params.splat !== undefined) {
// Express 5 wildcard route (/*splat)
// Handle array values - join them if array, otherwise use as-is
filePath = Array.isArray(req.params.splat) ? req.params.splat.join('/') : String(req.params.splat || '');
} else if (req.params && req.params[0] !== undefined) {
// Numbered parameter fallback
filePath = Array.isArray(req.params[0]) ? req.params[0].join('/') : String(req.params[0] || '');
} else if (req.baseUrl) {
// If there's a baseUrl, remove it from the path
filePath = requestPath.slice(req.baseUrl.length);
} else if (req.route && req.route.path === '/') {
// Root route - use full path minus leading slash
filePath = requestPath.slice(1);
} else {
// Fallback to the original slicing logic for compatibility
filePath = requestPath.slice(req.route.path.length - 1);
}
// Ensure filePath is a string and has no leading slash
filePath = String(filePath || '');
if (filePath.startsWith('/')) {
filePath = filePath.slice(1);
}
if (requestPath === '') {
console.log('replaced root with index.html');
filePath = 'index.html';