nestjs-rate-limiter
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -14,2 +14,5 @@ import { Reflector } from '@nestjs/core'; | ||
canActivate(context: ExecutionContext): Promise<boolean>; | ||
protected getIpFromRequest(request: { | ||
ip: string; | ||
}): string; | ||
private httpHandler; | ||
@@ -16,0 +19,0 @@ private setResponseHeaders; |
@@ -160,3 +160,3 @@ "use strict"; | ||
canActivate(context) { | ||
var _a, _b, _c, _d; | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -177,3 +177,3 @@ let points = ((_a = this.specificOptions) === null || _a === void 0 ? void 0 : _a.points) || this.options.points; | ||
const rateLimiter = yield this.getRateLimiter(reflectedOptions); | ||
const key = (_d = (_c = request.ip) === null || _c === void 0 ? void 0 : _c.match(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/)) === null || _d === void 0 ? void 0 : _d[0]; | ||
const key = this.getIpFromRequest(request); | ||
yield this.responseHandler(response, key, rateLimiter, points, pointsConsumed); | ||
@@ -183,2 +183,6 @@ return true; | ||
} | ||
getIpFromRequest(request) { | ||
var _a, _b; | ||
return (_b = (_a = request.ip) === null || _a === void 0 ? void 0 : _a.match(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/)) === null || _b === void 0 ? void 0 : _b[0]; | ||
} | ||
httpHandler(context) { | ||
@@ -185,0 +189,0 @@ if (this.options.for === 'ExpressGraphql') { |
{ | ||
"name": "nestjs-rate-limiter", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Highly configurable and extensible rate limiter library", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -52,2 +52,3 @@ <p align="center"> | ||
- [customResponseSchema](https://github.com/ozkanonur/nestjs-rate-limiter#-customResponseSchema) | ||
- [Override Functions](https://github.com/ozkanonur/nestjs-rate-limiter#override-functions) | ||
- [Benchmarks](https://github.com/ozkanonur/nestjs-rate-limiter#benchmarks) | ||
@@ -469,2 +470,18 @@ - [TODO List](https://github.com/ozkanonur/nestjs-rate-limiter#todo) | ||
customResponseSchema option allows to provide customizable response schemas | ||
# Override Functions | ||
#### It's possible to override <code> getIpFromRequest </code> function by extending <code> RateLimiterGuard </code> class. | ||
```ts | ||
import { RateLimiterGuard } from 'nestjs-rate-limiter' | ||
import type { Request } from 'express' | ||
class ExampleRateLimiterGuard extends RateLimiterGuard { | ||
protected getIpFromRequest(request: Request): string { | ||
return request.get('x-forwarded-for'); | ||
} | ||
} | ||
``` | ||
# Benchmarks | ||
@@ -471,0 +488,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57942
701
506