mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-25 17:08:35 +03:00
migrate to typescript
This commit is contained in:
committed by
Dainius Dauksevicius
parent
c462323dd5
commit
08d27265fc
19
src/utils/getIP.ts
Normal file
19
src/utils/getIP.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import {config} from '../config';
|
||||
import {Request} from 'express';
|
||||
|
||||
export function getIP(req: Request): string {
|
||||
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;
|
||||
case "Cloudflare":
|
||||
return req.headers['cf-connecting-ip'] as string;
|
||||
case "X-Real-IP":
|
||||
return req.headers['x-real-ip'] as string;
|
||||
default:
|
||||
return req.connection.remoteAddress;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user