-
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
Updated pr 110 #134
Updated pr 110 #134
Conversation
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.
move this to nestjs logger.
export class GeoIPInterceptor implements NestInterceptor { | ||
private readonly httpService: HttpService; | ||
private readonly allowedCountries: string[]; | ||
|
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.
register a logger attribute as well
private readonly logger: Logger ; |
throw new HttpException('Access Denied', HttpStatus.FORBIDDEN); | ||
} | ||
|
||
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.
move to nest js logger
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.
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); |
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.
move to NestJS logger.
).resolves.toBeInstanceOf(Observable); | ||
}); | ||
|
||
it('should block a request from outside India', async () => { |
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.
add more test cases:
- should block iPv6 outside india.
- should allow IPv4 outside India.
- should allow iPv6 outside India.
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.
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'; |
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.
import from package.
import { GeoIPInterceptor } from './geoip.interceptor'; | |
import { GeoIPInterceptor } from '@samagra-x/stencil'; |
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.
remove this file
Closing this since #137 builds on top of this. |
Description