Skip to content

Commit 2873feb

Browse files
update version
1 parent 504474e commit 2873feb

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "princejs",
3-
"version": "2.1.4",
3+
"version": "2.1.5",
44
"description": "An easy and fast backend framework that is among the top three — by a 13yo developer, for developers.",
55
"main": "dist/prince.js",
66
"types": "dist/prince.d.ts",

src/prince.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,19 @@ export class Prince {
794794
configurable: true,
795795
});
796796

797+
// Only parse body if it hasn't been parsed by middleware already
798+
if (["POST", "PUT", "PATCH"].includes(req.method) && !req.parsedBody) {
799+
const parsed = await this.parseBody(req);
800+
if (parsed) {
801+
if (typeof parsed === "object" && "files" in parsed && "fields" in parsed) {
802+
req.parsedBody = parsed.fields;
803+
req.files = parsed.files;
804+
} else {
805+
req.parsedBody = parsed;
806+
}
807+
}
808+
}
809+
797810
// Call onBeforeHandle hooks
798811
for (const hook of this.onBeforeHandleHooks) {
799812
await hook(req, pathname, method);
@@ -809,16 +822,6 @@ export class Prince {
809822
if (result instanceof Response) return result;
810823
}
811824

812-
// Parse body here — after all middleware has run — so middleware like
813-
// validate() can read/clone the raw stream first without it being consumed.
814-
// If middleware already set req.parsedBody (e.g. validate), skip parsing.
815-
if (["POST", "PUT", "PATCH"].includes(req.method) && !req.parsedBody) {
816-
const parsed = await this.parseBody(req);
817-
if (parsed !== null) {
818-
req.parsedBody = parsed;
819-
}
820-
}
821-
822825
const res = await handler(req);
823826
if (res instanceof Response) return res;
824827
if (res instanceof ResponseBuilder) return res.build();

0 commit comments

Comments
 (0)