Anpassungen zum Thema IP Resolving
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user