chanjs 2.0.20 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/helper/ip.js +0 -2
- package/index.js +3 -3
- package/package.json +1 -1
package/helper/ip.js
CHANGED
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
export const getIp = (req) => {
|
|
7
7
|
// 优先级从高到低获取可能的IP来源
|
|
8
8
|
const ipSources = [
|
|
9
|
-
req.headers["x-forwarded-for"], // 代理场景下的真实IP(可能多个,逗号分隔)
|
|
10
|
-
req.headers["x-real-ip"], // 部分代理服务器使用
|
|
11
9
|
req.ip, // Express内置的IP获取(已处理代理)
|
|
12
10
|
req.connection?.remoteAddress, // 底层连接的远程地址
|
|
13
11
|
req.socket?.remoteAddress, // 套接字的远程地址
|
package/index.js
CHANGED
|
@@ -67,9 +67,10 @@ class Chan {
|
|
|
67
67
|
statics,
|
|
68
68
|
logger,
|
|
69
69
|
cors,
|
|
70
|
+
PROXY,
|
|
70
71
|
} = Chan.config;
|
|
71
72
|
|
|
72
|
-
this.app.set("trust proxy", true);
|
|
73
|
+
this.app.set("trust proxy", PROXY === "true" ? true : false);
|
|
73
74
|
log(this.app, logger);
|
|
74
75
|
setFavicon(this.app);
|
|
75
76
|
setCookie(this.app, cookieKey);
|
|
@@ -166,11 +167,10 @@ class Chan {
|
|
|
166
167
|
path: r.route.path,
|
|
167
168
|
methods: Object.keys(r.route.methods),
|
|
168
169
|
}));
|
|
169
|
-
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
run(cb) {
|
|
173
|
-
const port = parseInt(
|
|
173
|
+
const port = parseInt(Chan.config.PORT) || 3000;
|
|
174
174
|
this.app.listen(port, () => {
|
|
175
175
|
cb ? cb(port) : console.log(`Server is running on port ${port}`);
|
|
176
176
|
});
|