@adaptivestone/framework 5.0.0-beta.31 → 5.0.0-beta.32
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/CHANGELOG.md
CHANGED
|
@@ -25,6 +25,7 @@ Main feature of that release is full TypeScript support insluding mongoose model
|
|
|
25
25
|
- **[NEW]** `IpDetector` middleware for detecting proxies and `X-Forwarded-For` headers.
|
|
26
26
|
- **[NEW]** Test helpers getTestServerURL and serverInstance.
|
|
27
27
|
- **[NEW]** Rate limiter middleware - add consumeResult function to allow user middleware as a regular rate limiter
|
|
28
|
+
- **[NEW]** Ip detector middleware - add getIpAdressFromIncomingMessage function to allow user middleware as a detector of id adresses without middleware
|
|
28
29
|
|
|
29
30
|
### Breaking changes (please read carefully)
|
|
30
31
|
|
|
@@ -47,6 +48,12 @@ Main feature of that release is full TypeScript support insluding mongoose model
|
|
|
47
48
|
- **[BREAKING]** ESM only. No more commonJS. That help to fix a lot of bugs with tests and provides better development expirience.
|
|
48
49
|
- **[BREAKING]** Mongoose v8. <https://mongoosejs.com/docs/migrating_to_8.html>.
|
|
49
50
|
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## [5.0.0-beta.32]
|
|
54
|
+
|
|
55
|
+
- **[NEW]** Ip detector middleware - add getIpAdressFromIncomingMessage function to allow user middleware as a detector of id adresses without middleware
|
|
56
|
+
|
|
50
57
|
|
|
51
58
|
---
|
|
52
59
|
|
|
@@ -55,8 +62,6 @@ Main feature of that release is full TypeScript support insluding mongoose model
|
|
|
55
62
|
- **[NEW]** Rate limiter middleware - add consumeResult function to allow user middleware as a regular rate limiter
|
|
56
63
|
|
|
57
64
|
|
|
58
|
-
---
|
|
59
|
-
|
|
60
65
|
---
|
|
61
66
|
|
|
62
67
|
## [5.0.0-beta.30]
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
1
2
|
import { BlockList } from 'node:net';
|
|
2
3
|
import type { NextFunction, Response } from 'express';
|
|
3
4
|
import type { IApp } from '../../../server.ts';
|
|
@@ -7,6 +8,7 @@ declare class IpDetector extends AbstractMiddleware {
|
|
|
7
8
|
static get description(): string;
|
|
8
9
|
blockList: BlockList;
|
|
9
10
|
constructor(app: IApp, params?: Record<string, unknown>);
|
|
11
|
+
getIpAdressFromIncomingMessage(req: IncomingMessage): string | undefined;
|
|
10
12
|
middleware(req: FrameworkRequest, _res: Response, next: NextFunction): Promise<void>;
|
|
11
13
|
}
|
|
12
14
|
export default IpDetector;
|
|
@@ -27,10 +27,10 @@ class IpDetector extends AbstractMiddleware {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
getIpAdressFromIncomingMessage(req) {
|
|
31
31
|
const { headers } = this.app.getConfig('ipDetector');
|
|
32
32
|
const initialIp = req.socket.remoteAddress;
|
|
33
|
-
|
|
33
|
+
let ip = initialIp;
|
|
34
34
|
const addressType = initialIp?.includes(':') ? 'ipv6' : 'ipv4';
|
|
35
35
|
if (this.blockList.check(initialIp ?? '', addressType)) {
|
|
36
36
|
// we can trust this source
|
|
@@ -39,11 +39,15 @@ class IpDetector extends AbstractMiddleware {
|
|
|
39
39
|
const ipHeader = req.headers[header.toLowerCase()];
|
|
40
40
|
if (ipHeader) {
|
|
41
41
|
const [firstIp] = ipHeader.split(',').map((ip) => ip.trim());
|
|
42
|
-
|
|
42
|
+
ip = firstIp;
|
|
43
43
|
break;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
return ip;
|
|
48
|
+
}
|
|
49
|
+
async middleware(req, _res, next) {
|
|
50
|
+
req.appInfo.ip = this.getIpAdressFromIncomingMessage(req);
|
|
47
51
|
next();
|
|
48
52
|
}
|
|
49
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IpDetector.js","sourceRoot":"","sources":["../../../../src/services/http/middleware/IpDetector.ts"],"names":[],"mappings":"
|
|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