🐞 fix(ip): 当有高防的时候获取真实ip
This commit is contained in:
@@ -2,10 +2,10 @@ import { Context } from 'egg';
|
|||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
return async function parmsDecode(ctx: Context, next) {
|
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]);
|
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;
|
ctx.clientIp = xTrueIp||xRealIp||ctx.request.ip;
|
||||||
console.log('*****', ctx.clientIp);
|
console.log('ip ', ctx.uid, ctx.request.url, ctx.clientIp);
|
||||||
await next();
|
await next();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user