Skip to content
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

Closed
wants to merge 6 commits into from
Closed

Updated pr 110 #134

wants to merge 6 commits into from

Conversation

RiyaRaj28
Copy link
Contributor

Description

  • Added configuration service

@RiyaRaj28 RiyaRaj28 changed the title Pr 110 Updated pr 110 Jun 18, 2024
this.allowedCountries.length > 0 &&
!this.allowedCountries.includes(country)
) {
console.log(
Copy link
Member

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[];

Copy link
Member

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

Suggested change
private readonly logger: Logger ;

throw new HttpException('Access Denied', HttpStatus.FORBIDDEN);
}

console.log(
Copy link
Member

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}`,
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to NestJS logger.

sample/07-geopip-blocking/src/app.controller.spec.ts Outdated Show resolved Hide resolved
).resolves.toBeInstanceOf(Observable);
});

it('should block a request from outside India', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add more test cases:

  1. should block iPv6 outside india.
  2. should allow IPv4 outside India.
  3. should allow iPv6 outside India.

Copy link
Member

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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import from package.

Suggested change
import { GeoIPInterceptor } from './geoip.interceptor';
import { GeoIPInterceptor } from '@samagra-x/stencil';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this file

@techsavvyash techsavvyash mentioned this pull request Jun 19, 2024
@techsavvyash
Copy link
Member

Closing this since #137 builds on top of this.

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

Successfully merging this pull request may close these issues.

3 participants