Skip to content

Commit fb41eaf

Browse files
willerheadaex
authored andcommitted
添加获取真实ip方法
1 parent 2934482 commit fb41eaf

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/service/CoaContext.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ export class CoaContext {
5454
return host.toString().split(',', 1)[0].trim() || ''
5555
}
5656

57+
// 获取真实ip地址
58+
get realIp () {
59+
const headers = this.req.headers
60+
const ips = headers['ali-cdn-real-ip'] || headers['x-original-forwarded-for'] || headers['x-real-ip'] || headers['x-forwarded-for'] || ''
61+
return ips.toString().split(',', 1)[0].trim()
62+
}
63+
5764
// 根据session名称,获取session信息,支持各种类型的参数,包括 query body headers
5865
session (name: string) {
5966
name = name.toLowerCase()

0 commit comments

Comments
 (0)