Files
ZYZ/web-server/app/middleware/getIp.ts
2021-12-08 17:35:23 +08:00

13 lines
342 B
TypeScript

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