Files
ZYZ/web-server/app/middleware/getIp.ts
2021-12-09 20:38:23 +08:00

13 lines
371 B
TypeScript

import { Context } from 'egg';
module.exports = () => {
return async function parmsDecode(ctx: Context, next) {
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);
await next();
};
};