mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-18 21:48:29 +03:00
Add type safety to getSkipSegments
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
import {config} from '../config';
|
||||
import {Request} from 'express';
|
||||
import { IPAddress } from '../types/segments.model';
|
||||
|
||||
export function getIP(req: Request): string {
|
||||
export function getIP(req: Request): IPAddress {
|
||||
if (config.behindProxy === true || config.behindProxy === "true") {
|
||||
config.behindProxy = "X-Forwarded-For";
|
||||
}
|
||||
|
||||
switch (config.behindProxy as string) {
|
||||
case "X-Forwarded-For":
|
||||
return req.headers['x-forwarded-for'] as string;
|
||||
return req.headers['x-forwarded-for'] as IPAddress;
|
||||
case "Cloudflare":
|
||||
return req.headers['cf-connecting-ip'] as string;
|
||||
return req.headers['cf-connecting-ip'] as IPAddress;
|
||||
case "X-Real-IP":
|
||||
return req.headers['x-real-ip'] as string;
|
||||
return req.headers['x-real-ip'] as IPAddress;
|
||||
default:
|
||||
return req.connection.remoteAddress;
|
||||
return req.connection.remoteAddress as IPAddress;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user