import { Context } from 'egg'; module.exports = () => { return async function parmsDecode(ctx: Context, next) { let clientIp = null; if (ctx.header['x-forwarded-for'] && (typeof ctx.header['x-forwarded-for'] == 'string')) { clientIp = ctx.header['x-forwarded-for'].split(',')[0]; console.log('***** xff', clientIp); } else { clientIp = ctx.header['x-real-ip'] && (typeof ctx.header['x-real-ip'] == 'string'? ctx.header['x-real-ip']: ctx.header['x-real-ip'][0]); console.log('***** real', clientIp); } ctx.clientIp = clientIp||ctx.request.ip; console.log('***** clientIp', ctx.clientIp); await next(); }; };