arcway 0.4.9 → 0.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server/router/routes.js +18 -2
package/package.json
CHANGED
package/server/router/routes.js
CHANGED
|
@@ -46,6 +46,13 @@ function prefixRoutePattern(pattern, prefix) {
|
|
|
46
46
|
if (pattern === '/') return normalized;
|
|
47
47
|
return normalized + pattern;
|
|
48
48
|
}
|
|
49
|
+
function defaultRateLimitKey(relativePath, method, prefix) {
|
|
50
|
+
let endpoint = relativePath.replace(/\\/g, '/').replace(/\.jsx?$/, '');
|
|
51
|
+
endpoint = endpoint.replace(/\/index$/, '');
|
|
52
|
+
if (endpoint === 'index') endpoint = '';
|
|
53
|
+
endpoint = prefixRoutePattern('/' + endpoint, prefix);
|
|
54
|
+
return `${endpoint}:${method.toLowerCase()}`;
|
|
55
|
+
}
|
|
49
56
|
function buildRoutesFromModules(entries, { prefix = '', plugin } = {}) {
|
|
50
57
|
const routes = [];
|
|
51
58
|
for (const { filePath, relativePath, module } of entries) {
|
|
@@ -65,13 +72,22 @@ function buildRoutesFromModules(entries, { prefix = '', plugin } = {}) {
|
|
|
65
72
|
throw new Error(`Route ${method} ${urlPattern} (${filePath}) ratelimit cannot be empty`);
|
|
66
73
|
}
|
|
67
74
|
config._parsedRateLimits = policies.map((policy, index) => {
|
|
68
|
-
if (!policy
|
|
75
|
+
if (!policy || typeof policy !== 'object') {
|
|
76
|
+
const suffix = policies.length > 1 ? `[${index}]` : '';
|
|
77
|
+
throw new Error(
|
|
78
|
+
`Route ${method} ${urlPattern} (${filePath}) ratelimit${suffix} must be an object`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
if (policy.key !== undefined && (typeof policy.key !== 'string' || !policy.key)) {
|
|
69
82
|
const suffix = policies.length > 1 ? `[${index}]` : '';
|
|
70
83
|
throw new Error(
|
|
71
84
|
`Route ${method} ${urlPattern} (${filePath}) ratelimit${suffix}.key must be a non-empty string`,
|
|
72
85
|
);
|
|
73
86
|
}
|
|
74
|
-
return {
|
|
87
|
+
return {
|
|
88
|
+
key: policy.key ?? defaultRateLimitKey(relativePath, method, prefix),
|
|
89
|
+
...parseRateLimit(policy.limit),
|
|
90
|
+
};
|
|
75
91
|
});
|
|
76
92
|
// Preserve the existing internal field for integrations that inspect a
|
|
77
93
|
// route with one rate-limit policy.
|