mirror of
https://github.com/wyb10a10/cocos_creator_framework.git
synced 2026-05-08 06:38:16 +08:00
16 lines
516 B
TypeScript
16 lines
516 B
TypeScript
import * as http from "http";
|
|
|
|
export class HttpUtil {
|
|
static getClientIp(req: http.IncomingMessage) {
|
|
var ipAddress;
|
|
var forwardedIpsStr = req.headers['x-forwarded-for'] as string | undefined;
|
|
if (forwardedIpsStr) {
|
|
var forwardedIps = forwardedIpsStr.split(',');
|
|
ipAddress = forwardedIps[0];
|
|
}
|
|
if (!ipAddress) {
|
|
ipAddress = req.socket.remoteAddress;
|
|
}
|
|
return ipAddress ? ipAddress.replace(/^::ffff:/, '') : '';
|
|
};
|
|
} |