titbit-toolkit
Version:
titbit框架的工具集,包括跨域、静态资源处理,权限过滤,请求计时,cookie,session,jwt等大量中间件
35 lines (22 loc) • 557 B
JavaScript
class RealIP {
constructor() {
}
mid() {
return async (c, next) => {
let realipstr = c.headers['x-real-ip'] || c.headers['x-forwarded-for'] || ''
if (realipstr !== '') {
if (realipstr.indexOf(',') > 0) {
c.box.realip = realipstr.split(',').filter(p => p.length > 0)
if (c.box.realip.length > 0) {
c.ip = c.box.realip[0].trim()
}
} else {
c.ip = realipstr
}
}
await next()
}
}
}
module.exports = RealIP