Skip to content

Commit

Permalink
fix(use/koa): Use the parsed request body rather than ctx.body (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmurzy authored Nov 6, 2024
1 parent 21aebc7 commit 9f8b1f1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"@types/glob": "^8.1.0",
"@types/html-validator": "^5.0.6",
"@types/k6": "^0.47.3",
"@types/koa": "^2.13.12",
"@types/koa": "^2.15.0",
"@types/koa-mount": "^4.0.5",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
Expand All @@ -140,7 +140,7 @@
"glob": "^10.3.10",
"graphql": "^16.8.1",
"html-validator": "^6.0.1",
"koa": "^2.14.2",
"koa": "^2.15.3",
"koa-mount": "^4.0.0",
"node-fetch": "^3.3.2",
"prettier": "^3.1.0",
Expand Down
4 changes: 2 additions & 2 deletions src/use/koa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ export function createHandler<Context extends OperationContext = undefined>(
method: ctx.method,
headers: ctx.headers,
body: () => {
if (ctx.body) {
if ('body' in ctx.request) {
// in case koa has a body parser
return ctx.body;
return ctx.request.body as Record<string, unknown>;
}
return new Promise<string>((resolve) => {
let body = '';
Expand Down
40 changes: 28 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4137,7 +4137,7 @@ __metadata:
languageName: node
linkType: hard

"@types/koa@npm:*, @types/koa@npm:^2.13.12":
"@types/koa@npm:*":
version: 2.13.12
resolution: "@types/koa@npm:2.13.12"
dependencies:
Expand All @@ -4153,6 +4153,22 @@ __metadata:
languageName: node
linkType: hard

"@types/koa@npm:^2.15.0":
version: 2.15.0
resolution: "@types/koa@npm:2.15.0"
dependencies:
"@types/accepts": "npm:*"
"@types/content-disposition": "npm:*"
"@types/cookies": "npm:*"
"@types/http-assert": "npm:*"
"@types/http-errors": "npm:*"
"@types/keygrip": "npm:*"
"@types/koa-compose": "npm:*"
"@types/node": "npm:*"
checksum: 2be9dff1ef66bf15b037386c188893761a8fb46390a5e1d2a2031d9e1ba4473e40ddfbd625980a504bd804d7148b3e230c18e240503f33eac3b6e5e830645d30
languageName: node
linkType: hard

"@types/long@npm:^4.0.0":
version: 4.0.2
resolution: "@types/long@npm:4.0.2"
Expand Down Expand Up @@ -5737,13 +5753,13 @@ __metadata:
languageName: node
linkType: hard

"cookies@npm:~0.8.0":
version: 0.8.0
resolution: "cookies@npm:0.8.0"
"cookies@npm:~0.9.0":
version: 0.9.1
resolution: "cookies@npm:0.9.1"
dependencies:
depd: "npm:~2.0.0"
keygrip: "npm:~1.1.0"
checksum: 5da4d72ba81c2740511751ac8ea9506e10e2366b9ad3360333581e4667fd8d063d02c5be0bef16177de3e366b8128ed2b72921e2952c79cbca084d177e529bba
checksum: 4816461a38d907b20f3fb7a2bc4741fe580e7a195f3e248ef7025cb3be56a07638a0f4e72553a5f535554ca30172c8a3245c63ac72c9737cec034e9a47773392
languageName: node
linkType: hard

Expand Down Expand Up @@ -7585,7 +7601,7 @@ __metadata:
"@types/glob": "npm:^8.1.0"
"@types/html-validator": "npm:^5.0.6"
"@types/k6": "npm:^0.47.3"
"@types/koa": "npm:^2.13.12"
"@types/koa": "npm:^2.15.0"
"@types/koa-mount": "npm:^4.0.5"
"@typescript-eslint/eslint-plugin": "npm:^6.13.2"
"@typescript-eslint/parser": "npm:^6.13.2"
Expand All @@ -7598,7 +7614,7 @@ __metadata:
glob: "npm:^10.3.10"
graphql: "npm:^16.8.1"
html-validator: "npm:^6.0.1"
koa: "npm:^2.14.2"
koa: "npm:^2.15.3"
koa-mount: "npm:^4.0.0"
node-fetch: "npm:^3.3.2"
prettier: "npm:^3.1.0"
Expand Down Expand Up @@ -8706,15 +8722,15 @@ __metadata:
languageName: node
linkType: hard

"koa@npm:^2.14.2":
version: 2.14.2
resolution: "koa@npm:2.14.2"
"koa@npm:^2.15.3":
version: 2.15.3
resolution: "koa@npm:2.15.3"
dependencies:
accepts: "npm:^1.3.5"
cache-content-type: "npm:^1.0.0"
content-disposition: "npm:~0.5.2"
content-type: "npm:^1.0.4"
cookies: "npm:~0.8.0"
cookies: "npm:~0.9.0"
debug: "npm:^4.3.2"
delegates: "npm:^1.0.0"
depd: "npm:^2.0.0"
Expand All @@ -8733,7 +8749,7 @@ __metadata:
statuses: "npm:^1.5.0"
type-is: "npm:^1.6.16"
vary: "npm:^1.1.2"
checksum: be3592ad2ed61068aaf19f4957de07602c4141cb33e049727d2453010d90cb9f4756c87103c9b44e24cf31f061116f4479b0a4ce7638c96fd64652f559ad5b7b
checksum: b2c2771a4ee5268f9d039ce025b9c3798a0baba8c3cf3895a6fc2d286363e0cd2c98c02a5b87f14100baa2bc17d854eed6ed80f9bd41afda1d056f803b206514
languageName: node
linkType: hard

Expand Down

0 comments on commit 9f8b1f1

Please sign in to comment.