mm_os 2.6.9 → 2.7.1
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.
|
@@ -7,13 +7,17 @@ const platform = os.platform();
|
|
|
7
7
|
/**
|
|
8
8
|
* 获取客户端IP
|
|
9
9
|
* @param {Object} req 请求对象
|
|
10
|
-
*
|
|
10
|
+
* @returns {String} 返回真实IP
|
|
11
11
|
*/
|
|
12
12
|
function getClientIP(req) {
|
|
13
|
-
|
|
13
|
+
var ip = req.headers['x-forwarded-for'] || req.headers['X-Forwarded-For'] || req.headers['x-real-ip'] ||
|
|
14
14
|
req.connection.remoteAddress ||
|
|
15
15
|
req.socket.remoteAddress ||
|
|
16
16
|
req.connection.socket.remoteAddress;
|
|
17
|
+
if (ip && ip.split(',').length > 0) {
|
|
18
|
+
ip = ip.split(',')[0]; // 取第一个IP地址
|
|
19
|
+
}
|
|
20
|
+
return ip;
|
|
17
21
|
};
|
|
18
22
|
|
|
19
23
|
/**
|
|
@@ -99,6 +103,7 @@ module.exports = function(server, config) {
|
|
|
99
103
|
time,
|
|
100
104
|
num
|
|
101
105
|
}), duration);
|
|
106
|
+
ctx.request.ip = ip;
|
|
102
107
|
await next();
|
|
103
108
|
} else {
|
|
104
109
|
ctx.status = 429;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_os",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.1",
|
|
4
4
|
"description": "这是超级美眉服务端框架,用于快速构建应用程序。",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"mm_machine": "^1.8.1",
|
|
45
45
|
"mm_mongodb": "^1.4.2",
|
|
46
46
|
"mm_mqtt": "^1.0.6",
|
|
47
|
-
"mm_mysql": "^1.8.
|
|
47
|
+
"mm_mysql": "^1.8.8",
|
|
48
48
|
"mm_os": "^2.6.4",
|
|
49
49
|
"mm_redis": "^1.4.2",
|
|
50
50
|
"mm_ret": "^1.3.9",
|