@tsed/platform-express 6.75.7 → 6.75.11
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.
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rawBodyMiddleware = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const bytes_1 = tslib_1.__importDefault(require("bytes"));
|
|
6
|
+
const limit = bytes_1.default.parse("100kb");
|
|
7
|
+
function isLimitReached(length) {
|
|
8
|
+
return limit !== null && length !== null && length > limit;
|
|
9
|
+
}
|
|
10
|
+
function getContentLength(request) {
|
|
11
|
+
const contentLength = request.get("content-length");
|
|
12
|
+
return contentLength != null && !isNaN(contentLength) ? parseInt(contentLength, 10) : null;
|
|
13
|
+
}
|
|
4
14
|
function rawBodyMiddleware(request, response, next) {
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
request.
|
|
8
|
-
request.rawBody
|
|
9
|
-
|
|
15
|
+
if (request.method !== "GET") {
|
|
16
|
+
const length = getContentLength(request);
|
|
17
|
+
if (!isLimitReached(length) && request.is(["application/x-www-form-urlencoded", "application/json"])) {
|
|
18
|
+
request.rawBody = "";
|
|
19
|
+
request.on("data", (chunk) => {
|
|
20
|
+
request.rawBody += chunk;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
10
23
|
}
|
|
11
24
|
next();
|
|
12
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rawBodyMiddleware.js","sourceRoot":"","sources":["../../src/middlewares/rawBodyMiddleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rawBodyMiddleware.js","sourceRoot":"","sources":["../../src/middlewares/rawBodyMiddleware.ts"],"names":[],"mappings":";;;;AACA,0DAA0B;AAE1B,MAAM,KAAK,GAAG,eAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAEnC,SAAS,cAAc,CAAC,MAAqB;IAC3C,OAAO,KAAK,KAAK,IAAI,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,GAAG,KAAK,CAAC;AAC7D,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAoC;IAC5D,MAAM,aAAa,GAAQ,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACzD,OAAO,aAAa,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7F,CAAC;AAED,SAAgB,iBAAiB,CAAC,OAAoC,EAAE,QAAa,EAAE,IAAS;IAC9F,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK,EAAE;QAC5B,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAEzC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,EAAE,CAAC,CAAC,mCAAmC,EAAE,kBAAkB,CAAC,CAAC,EAAE;YACpG,OAAO,CAAC,OAAO,GAAG,EAAE,CAAC;YACrB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;gBACnC,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC;YAC3B,CAAC,CAAC,CAAC;SACJ;KACF;IAED,IAAI,EAAE,CAAC;AACT,CAAC;AAbD,8CAaC","sourcesContent":["import {Request} from \"express\";\nimport bytes from \"bytes\";\n\nconst limit = bytes.parse(\"100kb\");\n\nfunction isLimitReached(length: number | null) {\n return limit !== null && length !== null && length > limit;\n}\n\nfunction getContentLength(request: Request & {rawBody: string}) {\n const contentLength: any = request.get(\"content-length\");\n return contentLength != null && !isNaN(contentLength) ? parseInt(contentLength, 10) : null;\n}\n\nexport function rawBodyMiddleware(request: Request & {rawBody: string}, response: any, next: any) {\n if (request.method !== \"GET\") {\n const length = getContentLength(request);\n\n if (!isLimitReached(length) && request.is([\"application/x-www-form-urlencoded\", \"application/json\"])) {\n request.rawBody = \"\";\n request.on(\"data\", (chunk: string) => {\n request.rawBody += chunk;\n });\n }\n }\n\n next();\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-express",
|
|
3
|
-
"version": "6.75.
|
|
3
|
+
"version": "6.75.11",
|
|
4
4
|
"description": "A TypeScript Framework on top of Express",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"tslib": "2.2.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@tsed/common": "6.75.
|
|
49
|
-
"@tsed/core": "6.75.
|
|
50
|
-
"@tsed/di": "6.75.
|
|
51
|
-
"@tsed/platform-test-utils": "6.75.
|
|
48
|
+
"@tsed/common": "6.75.11",
|
|
49
|
+
"@tsed/core": "6.75.11",
|
|
50
|
+
"@tsed/di": "6.75.11",
|
|
51
|
+
"@tsed/platform-test-utils": "6.75.11",
|
|
52
52
|
"@types/body-parser": "1.19.0",
|
|
53
53
|
"@types/compression": "1.7.0",
|
|
54
54
|
"@types/cookie-parser": "1.4.2",
|
|
@@ -64,13 +64,13 @@
|
|
|
64
64
|
"method-override": "3.0.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@tsed/common": "^6.75.
|
|
68
|
-
"@tsed/core": "^6.75.
|
|
69
|
-
"@tsed/di": "^6.75.
|
|
70
|
-
"@tsed/json-mapper": "^6.75.
|
|
67
|
+
"@tsed/common": "^6.75.11",
|
|
68
|
+
"@tsed/core": "^6.75.11",
|
|
69
|
+
"@tsed/di": "^6.75.11",
|
|
70
|
+
"@tsed/json-mapper": "^6.75.11",
|
|
71
71
|
"@tsed/logger": "^5.16.0",
|
|
72
|
-
"@tsed/openspec": "^6.75.
|
|
73
|
-
"@tsed/schema": "^6.75.
|
|
72
|
+
"@tsed/openspec": "^6.75.11",
|
|
73
|
+
"@tsed/schema": "^6.75.11",
|
|
74
74
|
"@types/multer": "^1.4.5",
|
|
75
75
|
"body-parser": "1.19.0"
|
|
76
76
|
}
|