Updated pr 110 - #134
Closed
RiyaRaj28 wants to merge 6 commits into
Closed
Conversation
techsavvyash
requested changes
Jun 19, 2024
| this.allowedCountries.length > 0 && | ||
| !this.allowedCountries.includes(country) | ||
| ) { | ||
| console.log( |
Member
There was a problem hiding this comment.
move this to nestjs logger.
| export class GeoIPInterceptor implements NestInterceptor { | ||
| private readonly httpService: HttpService; | ||
| private readonly allowedCountries: string[]; | ||
|
|
Member
There was a problem hiding this comment.
register a logger attribute as well
Suggested change
| private readonly logger: Logger ; |
| throw new HttpException('Access Denied', HttpStatus.FORBIDDEN); | ||
| } | ||
|
|
||
| console.log( |
| private async getLocation(ip: any): Promise<any> { | ||
| try { | ||
| const resp = await this.httpService.axiosRef.get( | ||
| `https://geoip.samagra.io/city/${ip}`, |
Member
There was a problem hiding this comment.
take this as a construction parameter of the interceptor and pass into this function from the intercept function above.
| ); | ||
| return { country: resp.data.country, regionName: resp.data.regionName }; | ||
| } catch (err) { | ||
| console.error('Error occured while reading the geoip database', err); |
| ).resolves.toBeInstanceOf(Observable); | ||
| }); | ||
|
|
||
| it('should block a request from outside India', async () => { |
Member
There was a problem hiding this comment.
add more test cases:
- should block iPv6 outside india.
- should allow IPv4 outside India.
- should allow iPv6 outside India.
Member
There was a problem hiding this comment.
remove this and import this from the package instead. Ideally the sample should be created after the interceptor has been released, you can do a local npm link based testing from the package.
| @@ -0,0 +1,11 @@ | |||
| import { NestFactory } from '@nestjs/core'; | |||
| import { AppModule } from './app.module'; | |||
| import { GeoIPInterceptor } from './geoip.interceptor'; | |||
Member
There was a problem hiding this comment.
import from package.
Suggested change
| import { GeoIPInterceptor } from './geoip.interceptor'; | |
| import { GeoIPInterceptor } from '@samagra-x/stencil'; |
Closed
1 task
Member
|
Closing this since #137 builds on top of this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description