13 lines
547 B
TypeScript
13 lines
547 B
TypeScript
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 = xTrueIp||xRealIp||ctx.request.ip;
|
|
console.log('ip ', ctx.uid, ctx.request.url, ctx.clientIp);
|
|
await next();
|
|
};
|
|
};
|
|
|