migrate to typescript

This commit is contained in:
Dainius Daukševičius
2020-10-17 21:56:54 +03:00
committed by Dainius Dauksevicius
parent c462323dd5
commit 08d27265fc
120 changed files with 5002 additions and 4711 deletions

19
src/utils/getIP.ts Normal file
View 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;
}
}