refactor: Upgrade path-to-regexp from 0.1.7 to 6.2.1 (#8558)

This commit is contained in:
Daniel
2023-05-23 00:39:32 +10:00
committed by GitHub
parent 00c362d739
commit 4c1093e2e4
4 changed files with 26 additions and 12 deletions

View File

@@ -82,9 +82,9 @@ const getRoute = parseClass => {
'@File': 'files',
}[parseClass] || 'classes';
if (parseClass === '@File') {
return `/${route}/:id?*`;
return `/${route}/:id?(.*)`;
}
return `/${route}/${parseClass}/:id?*`;
return `/${route}/${parseClass}/:id?(.*)`;
};
/** @namespace
* @name Parse

View File

@@ -9,7 +9,7 @@ import MongoStorageAdapter from './Adapters/Storage/Mongo/MongoStorageAdapter';
import PostgresStorageAdapter from './Adapters/Storage/Postgres/PostgresStorageAdapter';
import rateLimit from 'express-rate-limit';
import { RateLimitOptions } from './Options/Definitions';
import pathToRegexp from 'path-to-regexp';
import { pathToRegexp } from 'path-to-regexp';
import ipRangeCheck from 'ip-range-check';
import RedisStore from 'rate-limit-redis';
import { createClient } from 'redis';
@@ -512,8 +512,12 @@ export const addRateLimit = (route, config, cloud) => {
},
});
}
let transformPath = route.requestPath.replaceAll('/*', '/(.*)');
if (transformPath === '*') {
transformPath = '(.*)';
}
config.rateLimits.push({
path: pathToRegexp(route.requestPath),
path: pathToRegexp(transformPath),
handler: rateLimit({
windowMs: route.requestTimeWindow,
max: route.requestCount,