Skip to content

Updated pr 110 - #134

Closed
RiyaRaj28 wants to merge 6 commits into
SamagraX-Stencil:mainfrom
RiyaRaj28:pr-110
Closed

Updated pr 110#134
RiyaRaj28 wants to merge 6 commits into
SamagraX-Stencil:mainfrom
RiyaRaj28:pr-110

Conversation

@RiyaRaj28

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

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

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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