mirror of
https://github.com/sakaljurgis/kodi-api-server.git
synced 2026-07-08 20:37:41 +00:00
add x-forwarded-for to log for reverse proxy
This commit is contained in:
@@ -14,13 +14,16 @@ export class RequestLogMiddleware implements NestMiddleware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private extractIp(req: Request): string {
|
private extractIp(req: Request): string {
|
||||||
|
if (req.header('x-forwarded-for')) {
|
||||||
|
return req.header('x-forwarded-for');
|
||||||
|
}
|
||||||
|
|
||||||
let strIP = 'unk_IP';
|
let strIP = 'unk_IP';
|
||||||
const strRemoteAddress = req.socket.remoteAddress;
|
const strRemoteAddress = req.socket.remoteAddress;
|
||||||
if (strRemoteAddress != undefined) {
|
if (strRemoteAddress != undefined) {
|
||||||
strIP = strRemoteAddress.substring(strRemoteAddress.lastIndexOf(':') + 1);
|
strIP = strRemoteAddress.substring(strRemoteAddress.lastIndexOf(':') + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo - x-forwarded-for
|
|
||||||
if (!strIP || strIP === '1') {
|
if (!strIP || strIP === '1') {
|
||||||
if (req.hostname === 'localhost') {
|
if (req.hostname === 'localhost') {
|
||||||
strIP = '127.0.0.1';
|
strIP = '127.0.0.1';
|
||||||
|
|||||||
Reference in New Issue
Block a user