powr-sdk-api 4.8.1 → 4.8.3
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/dist/utils/getClientIp.js +8 -27
- package/package.json +1 -1
|
@@ -1,38 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Best-effort client IP from the incoming HTTP request
|
|
5
|
-
* (uses X-Forwarded-For, X-Real-IP, req.ip, or socket address).
|
|
3
|
+
/**
|
|
4
|
+
* Best-effort client IP from the incoming HTTP request
|
|
5
|
+
* (uses X-Forwarded-For, X-Real-IP, req.ip, or socket address).
|
|
6
6
|
*/
|
|
7
7
|
function getClientIp(req) {
|
|
8
8
|
const forwarded = req.headers["x-forwarded-for"];
|
|
9
|
-
const realIp = req.headers["x-real-ip"];
|
|
10
9
|
if (typeof forwarded === "string" && forwarded.length > 0) {
|
|
11
10
|
const first = forwarded.split(",")[0].trim();
|
|
12
|
-
if (first)
|
|
13
|
-
console.log("[getClientIp] using x-forwarded-for:", first);
|
|
14
|
-
return first;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if (typeof realIp === "string" && realIp.trim()) {
|
|
18
|
-
const v = realIp.trim();
|
|
19
|
-
console.log("[getClientIp] using x-real-ip:", v);
|
|
20
|
-
return v;
|
|
21
|
-
}
|
|
22
|
-
if (req.ip) {
|
|
23
|
-
console.log("[getClientIp] using req.ip:", req.ip);
|
|
24
|
-
return req.ip;
|
|
11
|
+
if (first) return first;
|
|
25
12
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
console.log("[getClientIp] no IP found", {
|
|
31
|
-
"x-forwarded-for": forwarded,
|
|
32
|
-
"x-real-ip": realIp,
|
|
33
|
-
reqIp: req.ip,
|
|
34
|
-
remoteAddress: req.socket && req.socket.remoteAddress
|
|
35
|
-
});
|
|
13
|
+
const realIp = req.headers["x-real-ip"];
|
|
14
|
+
if (typeof realIp === "string" && realIp.trim()) return realIp.trim();
|
|
15
|
+
if (req.ip) return req.ip;
|
|
16
|
+
if (req.socket && req.socket.remoteAddress) return req.socket.remoteAddress;
|
|
36
17
|
return null;
|
|
37
18
|
}
|
|
38
19
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "powr-sdk-api",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.3",
|
|
4
4
|
"description": "Shared API core library for PowrStack projects. Zero dependencies - works with Express, Next.js API routes, and other frameworks. All features are optional and install only what you need.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|