-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Geoip blocking #110
Geoip blocking #110
Conversation
@@ -0,0 +1,8 @@ | |||
{ | |||
"$schema": "https://json.schemastore.org/nest-cli", | |||
"collection": "@nestjs/schematics", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be @samagra-x/schematics
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", | ||
"start": "nest start", | ||
"start:dev": "nest start --watch", | ||
"start:debug": "nest start --debug --watch", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these three need to start with stencil
instead of nest
for being compatible with stencil-cli.
Need to also install @samagra-x/stencil-cli
and @samagra-x/schematics
in the project
this.allowedCountries.length > 0 && | ||
!this.allowedCountries.includes(country) | ||
) { | ||
console.log( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be console.error
private async getLocation(ip: any): Promise<any> { | ||
try { | ||
const resp = await this.httpService.axiosRef.get( | ||
`https://geoip.samagra.io/city/${ip}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we pick this from the environment using something like a configService
next: CallHandler, | ||
): Promise<Observable<any>> { | ||
const request = context.switchToHttp().getRequest(); | ||
const clientIp = request.headers['x-forwarded-for'] || request.ip; // Get client IP address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
closing this since #134 incorporates this. |
Resolves #44
How to Use the Interceptor
We get the user's location using the IP(v4, v6) address of the user and Samagra database using Axios command:
To use the GeoIPInterceptor globally in your application, you need to add it with an array of allowed countries. If the array is empty, all countries will be permitted.
In this example, the GeoIPInterceptor is configured to allow only requests from India.