Skip to content

Commit

Permalink
添加获取真实ip方法
Browse files Browse the repository at this point in the history
  • Loading branch information
willerhe authored and adaex committed May 11, 2021
1 parent 2934482 commit fb41eaf
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/service/CoaContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ export class CoaContext {
return host.toString().split(',', 1)[0].trim() || ''
}

// 获取真实ip地址
get realIp () {
const headers = this.req.headers
const ips = headers['ali-cdn-real-ip'] || headers['x-original-forwarded-for'] || headers['x-real-ip'] || headers['x-forwarded-for'] || ''
return ips.toString().split(',', 1)[0].trim()
}

// 根据session名称,获取session信息,支持各种类型的参数,包括 query body headers
session (name: string) {
name = name.toLowerCase()
Expand Down

0 comments on commit fb41eaf

Please sign in to comment.