Skip to content
This repository has been archived by the owner on Nov 23, 2022. It is now read-only.

Adding getIpFromRequest method to get the request's IP #84

Merged
merged 2 commits into from
Dec 1, 2021
Merged

Adding getIpFromRequest method to get the request's IP #84

merged 2 commits into from
Dec 1, 2021

Conversation

Borales
Copy link
Contributor

@Borales Borales commented Nov 30, 2021

Our project sits behind the proxy, so we need to get IP from the headers (x-forwarded-for).

If necessary, a developer could extend RateLimiterGuard class and override the getIpFromRequest method:

import { RateLimiterGuard } from 'nestjs-rate-limiter'
import type { Request } from 'express'

class MyRateLimiterGuard extends RateLimiterGuard {
  protected getIpFromRequest(request: Request): string {
    return request.get('x-forwarded-for');
  }
}

This would also help to solve the problem mentioned here:

import { RateLimiterGuard } from 'nestjs-rate-limiter'
import type { Request } from 'express'
import * as requestIp from 'request-ip'

class MyRateLimiterGuard extends RateLimiterGuard {
  protected getIpFromRequest(request: Request): string {
    return requestIp.getClientIp(request);
  }
}

@onur-ozkan
Copy link
Owner

Thank you for contributing!

@onur-ozkan onur-ozkan changed the base branch from master to dev December 1, 2021 08:04
@onur-ozkan onur-ozkan merged commit 47aa10d into onur-ozkan:dev Dec 1, 2021
@Borales Borales deleted the request-ip-method branch December 1, 2021 08:12
@Borales
Copy link
Contributor Author

Borales commented Dec 1, 2021

@ozkanonur would it be possible to release 3.0.1 with this change? It kinda blocks our integration (ip is undefined for us, so it's not really limiting the requests at the moment)

onur-ozkan added a commit that referenced this pull request Dec 1, 2021
* Adding getIpFromRequest method to get the request's IP (#84)

* upgrade to v3.1.0

Co-authored-by: Oleksandr Bordun <bordun.alexandr@gmail.com>
@onur-ozkan
Copy link
Owner

@ozkanonur would it be possible to release 3.0.1 with this change? It kinda blocks our integration (ip is undefined for us, so it's not really limiting the requests at the moment)

I just published v3.1.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants