🐞 fix(ip): 当有高防的时候获取真实ip

This commit is contained in:
luying
2023-05-12 20:11:07 +08:00
parent 0ba10b6bf8
commit be4541e02d

View File

@@ -2,10 +2,10 @@ import { Context } from 'egg';
module.exports = () => {
return async function parmsDecode(ctx: Context, next) {
let xTrueIp = ctx.header['x-true-ip'] && (typeof ctx.header['x-true-ip'] == 'string'? ctx.header['x-true-ip']: ctx.header['x-true-ip'][0]);
let xRealIp = ctx.header['x-real-ip'] && (typeof ctx.header['x-real-ip'] == 'string'? ctx.header['x-real-ip']: ctx.header['x-real-ip'][0]);
ctx.clientIp = xRealIp||ctx.request.ip;
console.log('*****', ctx.clientIp);
ctx.clientIp = xTrueIp||xRealIp||ctx.request.ip;
console.log('ip ', ctx.uid, ctx.request.url, ctx.clientIp);
await next();
};
};