Anpassungen zum Thema IP Resolving

This commit is contained in:
2024-09-12 16:01:41 +02:00
parent 68d2615f0f
commit 77c9973256
3 changed files with 14 additions and 7 deletions

View File

@@ -1,7 +1,11 @@
import { Body, Controller, Get, Ip, Param, Post } from '@nestjs/common';
import { Body, Controller, createParamDecorator, ExecutionContext, Get, Param, Post } from '@nestjs/common';
import { CountyRequest } from 'src/models/server.model';
import { GeoService } from './geo.service';
export const RealIp = createParamDecorator((data: unknown, ctx: ExecutionContext) => {
const request = ctx.switchToHttp().getRequest();
const realIp = request.headers['x-real-ip'] || request.headers['x-forwarded-for']?.split(',')[0] || request.connection.remoteAddress;
return realIp;
});
@Controller('geo')
export class GeoController {
constructor(private geoService: GeoService) {}
@@ -25,7 +29,7 @@ export class GeoController {
return this.geoService.findCountiesStartingWith(countyRequest.prefix, countyRequest.states);
}
@Get('ipinfo/georesult/wysiwyg')
fetchIpAndGeoLocation(@Ip() userIp: string): any {
fetchIpAndGeoLocation(@RealIp() userIp: string): any {
return this.geoService.fetchIpAndGeoLocation(userIp);
}
}