faltten strin[]
Jenkins Trigger / trigger_jenkins (push) Waiting to run Details

This commit is contained in:
Artur Kuś 2025-09-10 16:48:19 +02:00
parent ce5e22b968
commit 7e494d63eb
1 changed files with 24 additions and 5 deletions

View File

@ -32,8 +32,14 @@ export class Redirector {
if (this.urls.length === 0) {
(app._router.stack as any[]).forEach((middleware: any) => {
if (middleware.route?.path && middleware.route.methods.get) {
this.urls.push(middleware.route.path);
const routePath = middleware.route?.path;
if (routePath && middleware.route.methods.get) {
if (Array.isArray(routePath)) {
// np. ['/home', '/index']
this.urls.push(...routePath);
} else if (typeof routePath === 'string') {
this.urls.push(routePath);
}
}
});
}
@ -131,12 +137,25 @@ export class Redirector {
res: Response,
minRating: number = 0.8,
): boolean {
const urls = this.getAllGetUrls();
const match = stringSimilarity.findBestMatch(req.path, urls);
const urls: unknown = this.getAllGetUrls();
const requestUrl: unknown = req.path;
if (typeof requestUrl !== 'string') {
console.error('Invalid requestUrl', requestUrl);
return false;
}
if (!Array.isArray(urls) || !urls.every((u) => typeof u === 'string')) {
console.error('Invalid urls array', urls);
return false;
}
const match = stringSimilarity.findBestMatch(requestUrl, urls);
if (match.bestMatch.rating >= minRating) {
console.warn(
`[${Date.now()}] Similarity redirect (${match.bestMatch.rating.toFixed(2)}): ${req.path} -> ${match.bestMatch.target}`,
`[${Date.now()}] Similarity redirect (${match.bestMatch.rating.toFixed(
2,
)}): ${requestUrl} -> ${match.bestMatch.target}`,
);
res.redirect(301, match.bestMatch.target);
return true;