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:
@@ -16,7 +16,31 @@ export class HandlerProxy extends Handler {
|
||||
}
|
||||
) {
|
||||
super('ALL', async (req, res) => {
|
||||
const relativeRequestPath = req.path.slice(req.route.path.length - 1);
|
||||
// Extract the path using Express 5's params or fallback methods
|
||||
let relativeRequestPath: string;
|
||||
if (req.params && req.params.splat !== undefined) {
|
||||
// Express 5 wildcard route (/*splat)
|
||||
// Handle array values - join them if array, otherwise use as-is
|
||||
relativeRequestPath = Array.isArray(req.params.splat) ? req.params.splat.join('/') : String(req.params.splat || '');
|
||||
} else if (req.params && req.params[0] !== undefined) {
|
||||
// Numbered parameter fallback
|
||||
relativeRequestPath = 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
|
||||
relativeRequestPath = req.path.slice(req.baseUrl.length);
|
||||
} else if (req.route && req.route.path === '/') {
|
||||
// Root route - use full path minus leading slash
|
||||
relativeRequestPath = req.path.slice(1);
|
||||
} else {
|
||||
// Fallback to the original slicing logic for compatibility
|
||||
relativeRequestPath = req.path.slice(req.route.path.length - 1);
|
||||
}
|
||||
|
||||
// Ensure relativeRequestPath is a string and has no leading slash
|
||||
relativeRequestPath = String(relativeRequestPath || '');
|
||||
if (relativeRequestPath.startsWith('/')) {
|
||||
relativeRequestPath = relativeRequestPath.slice(1);
|
||||
}
|
||||
const proxyRequestUrl = remoteMountPointArg + relativeRequestPath;
|
||||
console.log(`proxy ${req.path} to ${proxyRequestUrl}`);
|
||||
let proxiedResponse: plugins.smartrequest.ICoreResponse;
|
||||
|
Reference in New Issue
Block a user