faltten strin[]
Jenkins Trigger / trigger_jenkins (push) Waiting to run
Details
Jenkins Trigger / trigger_jenkins (push) Waiting to run
Details
This commit is contained in:
parent
ce5e22b968
commit
7e494d63eb
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue