@harshror77/rate-limiter-sdk 1.0.1 → 1.0.3
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
CHANGED
package/src/RateLimiterClient.js
CHANGED
|
@@ -2,7 +2,6 @@ import axios from 'axios';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
|
|
5
|
-
// Extract the project name from the host environment ONCE when the SDK is initialized
|
|
6
5
|
let autoProjectName = 'Unknown Project';
|
|
7
6
|
try {
|
|
8
7
|
const pkgPath = path.resolve(process.cwd(), 'package.json');
|
|
@@ -13,7 +12,6 @@ try {
|
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
} catch (e) {
|
|
16
|
-
// Fail silently if package.json cannot be read, default to 'Unknown Project'
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
export class RateLimiterClient {
|
|
@@ -31,7 +29,7 @@ export class RateLimiterClient {
|
|
|
31
29
|
const response = await this.http.post('/api/check', request, {
|
|
32
30
|
headers: {
|
|
33
31
|
'x-api-key': this.apiKey,
|
|
34
|
-
'x-client-name': autoProjectName
|
|
32
|
+
'x-client-name': autoProjectName
|
|
35
33
|
},
|
|
36
34
|
});
|
|
37
35
|
return response.data;
|
|
@@ -4,6 +4,10 @@ export function RateLimiterMiddleware({ serviceUrl, apiKey, timeout, onLimitExce
|
|
|
4
4
|
const client = new RateLimiterClient({ serviceUrl, apiKey, timeout });
|
|
5
5
|
|
|
6
6
|
return async function (req, res, next) {
|
|
7
|
+
if (req.method === 'OPTIONS' || req.originalUrl === '/favicon.ico') {
|
|
8
|
+
return next();
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
try {
|
|
8
12
|
const result = await client.check({
|
|
9
13
|
ip: req.ip,
|