structured-fw 1.7.1 → 1.7.2
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/README.md
CHANGED
|
@@ -273,6 +273,11 @@ class RequestContext<Body extends LooseObject | undefined = LooseObject> = {
|
|
|
273
273
|
request: IncomingMessage;
|
|
274
274
|
response: ServerResponse;
|
|
275
275
|
|
|
276
|
+
// client IP address as determined by common header names
|
|
277
|
+
// falls back to request.socket.remoteAddress
|
|
278
|
+
// null if all attempts to determine the IP address have failed
|
|
279
|
+
ipAddress: string | null;
|
|
280
|
+
|
|
276
281
|
// captured URI arguments
|
|
277
282
|
// for example if the requested URI was /users/8 and the pattern was /users/(userId:num)
|
|
278
283
|
// args will be { userId: 8 }
|
|
@@ -11,6 +11,7 @@ export declare class RequestContext<Body extends LooseObject | undefined = Loose
|
|
|
11
11
|
private readonly handler;
|
|
12
12
|
readonly request: IncomingMessage;
|
|
13
13
|
readonly response: ServerResponse;
|
|
14
|
+
ipAddress: string | null;
|
|
14
15
|
args: URIArguments;
|
|
15
16
|
cookies: Record<string, string>;
|
|
16
17
|
body: Body;
|
|
@@ -41,4 +42,5 @@ export declare class RequestContext<Body extends LooseObject | undefined = Loose
|
|
|
41
42
|
duration(): number;
|
|
42
43
|
complete(): boolean;
|
|
43
44
|
isAsset(): boolean;
|
|
45
|
+
private requestIPAddress;
|
|
44
46
|
}
|
|
@@ -14,6 +14,7 @@ export class RequestContext {
|
|
|
14
14
|
handler;
|
|
15
15
|
request;
|
|
16
16
|
response;
|
|
17
|
+
ipAddress = null;
|
|
17
18
|
args = {};
|
|
18
19
|
cookies = {};
|
|
19
20
|
body;
|
|
@@ -32,6 +33,7 @@ export class RequestContext {
|
|
|
32
33
|
this.response = response;
|
|
33
34
|
this.handler = handler;
|
|
34
35
|
this.body = undefined;
|
|
36
|
+
this.ipAddress = this.requestIPAddress();
|
|
35
37
|
}
|
|
36
38
|
async exec() {
|
|
37
39
|
if (this.executionStartedAt !== null) {
|
|
@@ -332,4 +334,32 @@ export class RequestContext {
|
|
|
332
334
|
});
|
|
333
335
|
});
|
|
334
336
|
}
|
|
337
|
+
requestIPAddress() {
|
|
338
|
+
const headerList = [
|
|
339
|
+
'x-client-ip',
|
|
340
|
+
'x-real-ip',
|
|
341
|
+
'cf-connecting-ip',
|
|
342
|
+
'true-client-ip',
|
|
343
|
+
'x-cluster-client-ip',
|
|
344
|
+
'x-forwarded-for',
|
|
345
|
+
];
|
|
346
|
+
for (const headerName of headerList) {
|
|
347
|
+
if (headerName in this.request.headers) {
|
|
348
|
+
const value = this.request.headers[headerName];
|
|
349
|
+
if (typeof value === 'string' && value.trim().length > 0) {
|
|
350
|
+
if (headerName === 'x-forwarded-for') {
|
|
351
|
+
const ips = value.split(',');
|
|
352
|
+
const ip = ips[0].trim();
|
|
353
|
+
if (ip.length > 0) {
|
|
354
|
+
return ip;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
return value.trim();
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return this.request.socket.remoteAddress || null;
|
|
364
|
+
}
|
|
335
365
|
}
|
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"type": "module",
|
|
21
21
|
"main": "build/index",
|
|
22
|
-
"version": "1.7.
|
|
22
|
+
"version": "1.7.2",
|
|
23
23
|
"scripts": {
|
|
24
24
|
"develop": "tsc --watch",
|
|
25
25
|
"startDev": "cd build && nodemon --watch '../app/**/*' --watch '../build/**/*' -e js,html,hbs,css index.js",
|