Skip to content

Commit

Permalink
fix: add body parser to koa adapter, closes #841
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Oct 23, 2024
1 parent a095204 commit 60952e8
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 59 deletions.
4 changes: 2 additions & 2 deletions examples/with-koa/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const redisOptions = {

const createQueueMQ = (name) => new QueueMQ(name, { connection: redisOptions });

async function setupBullMQProcessor(queueName) {
function setupBullMQProcessor(queueName) {
new Worker(
queueName,
async (job) => {
Expand Down Expand Up @@ -71,7 +71,7 @@ const run = async () => {
await app.listen(3000);
// eslint-disable-next-line no-console
console.log('Running on 3000...');
console.log('For the UI of instance1, open http://localhost:3000/ui');
console.log('For the UI, open http://localhost:3000/ui');
console.log('Make sure Redis is running on port 6379 by default');
console.log('To populate the queue, run:');
console.log(' curl http://localhost:3000/add?title=Example');
Expand Down
8 changes: 5 additions & 3 deletions packages/koa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@
"dependencies": {
"@bull-board/api": "6.2.4",
"@bull-board/ui": "6.2.4",
"@koa/bodyparser": "^5.1.1",
"ejs": "^3.1.10",
"koa": "^2.13.1",
"koa": "^2.15.3",
"koa-mount": "^4.0.0",
"koa-router": "^10.0.0",
"koa-router": "^13.0.1",
"koa-static": "^5.0.0",
"koa-views": "^7.0.1"
"koa-views": "^8.1.0"
},
"devDependencies": {
"@types/co-body": "^6.1.3",
"@types/koa": "^2.13.3",
"@types/koa-mount": "^4.0.0",
"@types/koa-router": "^7.4.2",
Expand Down
4 changes: 3 additions & 1 deletion packages/koa/src/KoaAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import Koa from 'koa';
import mount from 'koa-mount';
import Router from 'koa-router';
import { bodyParser } from '@koa/bodyparser';
import serve from 'koa-static';
import views from 'koa-views';
import path from 'path';
Expand Down Expand Up @@ -91,6 +92,7 @@ export class KoaAdapter implements IServerAdapter {
strict: true,
});

app.use(bodyParser());
app.use(async (ctx, next) => {
try {
await next();
Expand Down Expand Up @@ -135,7 +137,7 @@ export class KoaAdapter implements IServerAdapter {
queues: this.bullBoardQueues as any,
params: ctx.params,
query: ctx.query,
body: ctx.body,
body: ctx.request.body,
});

ctx.status = response.status || 200;
Expand Down
112 changes: 59 additions & 53 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,15 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@koa/bodyparser@^5.1.1":
version "5.1.1"
resolved "https://registry.yarnpkg.com/@koa/bodyparser/-/bodyparser-5.1.1.tgz#cda8df0bc89339d6d9856ddee0d59f2ff3133d06"
integrity sha512-ZBF49xqNVxnmJ+8iXegq+fXPQm9RSX8giNl/aXS5rW1VpNct92wnFbGR/47vfoRJVLARGQ4HVL4WaQ0u8IJVoA==
dependencies:
co-body "^6.1.0"
lodash.merge "^4.6.2"
type-is "^1.6.18"

"@ladjs/consolidate@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@ladjs/consolidate/-/consolidate-1.0.1.tgz#95740c59b1c5b46e9894d14295347de381cef610"
Expand Down Expand Up @@ -3227,6 +3236,14 @@
"@types/connect" "*"
"@types/node" "*"

"@types/co-body@^6.1.3":
version "6.1.3"
resolved "https://registry.yarnpkg.com/@types/co-body/-/co-body-6.1.3.tgz#201796c6389066b400cfcb4e1ec5c3db798265a2"
integrity sha512-UhuhrQ5hclX6UJctv5m4Rfp52AfG9o9+d9/HwjxhVB5NjXxr5t9oKgJxN8xRHgr35oo8meUEHUPFWiKg6y71aA==
dependencies:
"@types/node" "*"
"@types/qs" "*"

"@types/connect@*":
version "3.4.35"
resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.35.tgz#5fcf6ae445e4021d1fc2219a4873cc73a3bb2ad1"
Expand Down Expand Up @@ -3546,7 +3563,7 @@
resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.4.tgz#cd667bcfdd025213aafb7ca5915a932590acdcdc"
integrity sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==

"@types/react-dom@17.0.20", "@types/react-dom@^17.0.14":
"@types/react-dom@^17.0.14":
version "17.0.20"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.20.tgz#e0c8901469d732b36d8473b40b679ad899da1b53"
integrity sha512-4pzIjSxDueZZ90F52mU3aPoogkHIoSIDG+oQ+wQK7Cy2B9S+MvOqY0uEA/qawKz381qrEDkvpwyt8Bm31I8sbA==
Expand Down Expand Up @@ -3577,7 +3594,7 @@
"@types/history" "^4.7.11"
"@types/react" "*"

"@types/react@*", "@types/react@17.0.63", "@types/react@^17", "@types/react@^17.0.14":
"@types/react@*", "@types/react@^17", "@types/react@^17.0.14":
version "17.0.63"
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.63.tgz#78ca41a34b1e4fd5ba9398d33bc78a81bfd5c180"
integrity sha512-T+aaG8RlIkgJ4VzWLJYbMW9QX7sIAV8CcuyV6FU6Hm7yu3Bee1YBZQRu2vYEm/dU8kre+/mzl2aGYh5MFgVLaQ==
Expand Down Expand Up @@ -4467,11 +4484,6 @@ bl@^5.0.0:
inherits "^2.0.4"
readable-stream "^3.4.0"

bluebird@^3.7.2:
version "3.7.2"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==

body-parser@1.20.3:
version "1.20.3"
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.3.tgz#1953431221c6fb5cd63c4b36d53fab0928e548c6"
Expand Down Expand Up @@ -4941,6 +4953,17 @@ cmd-shim@^4.1.0:
dependencies:
mkdirp-infer-owner "^2.0.0"

co-body@^6.1.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/co-body/-/co-body-6.2.0.tgz#afd776d60e5659f4eee862df83499698eb1aea1b"
integrity sha512-Kbpv2Yd1NdL1V/V4cwLVxraHDV6K8ayohr2rmH0J87Er8+zJjcTa6dAn9QMPC9CRgU8+aNajKbSf1TzDB1yKPA==
dependencies:
"@hapi/bourne" "^3.0.0"
inflation "^2.0.0"
qs "^6.5.2"
raw-body "^2.3.3"
type-is "^1.6.16"

co@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
Expand Down Expand Up @@ -5136,13 +5159,6 @@ console-control-strings@^1.0.0, console-control-strings@~1.1.0:
resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e"
integrity sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==

consolidate@^0.16.0:
version "0.16.0"
resolved "https://registry.yarnpkg.com/consolidate/-/consolidate-0.16.0.tgz#a11864768930f2f19431660a65906668f5fbdc16"
integrity sha512-Nhl1wzCslqXYTJVDyJCu3ODohy9OfBMB5uD2BiBTzd7w+QY0lBzafkR8y8755yMYHAaMD4NuzbAw03/xzfw+eQ==
dependencies:
bluebird "^3.7.2"

content-disposition@0.5.4, content-disposition@^0.5.4, content-disposition@~0.5.2:
version "0.5.4"
resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.4.tgz#8b82b4efac82512a02bb0b1dcec9d2c5e8eb5bfe"
Expand Down Expand Up @@ -5272,10 +5288,10 @@ cookiejar@^2.1.4:
resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-2.1.4.tgz#ee669c1fea2cf42dc31585469d193fef0d65771b"
integrity sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==

cookies@~0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/cookies/-/cookies-0.8.0.tgz#1293ce4b391740a8406e3c9870e828c4b54f3f90"
integrity sha512-8aPsApQfebXnuI+537McwYsDtjVxGm8gTIzQI3FDW6t5t/DAhERxtnbEPN/8RX+uZthoz4eCOgloXaE5cYyNow==
cookies@~0.9.0:
version "0.9.1"
resolved "https://registry.yarnpkg.com/cookies/-/cookies-0.9.1.tgz#3ffed6f60bb4fb5f146feeedba50acc418af67e3"
integrity sha512-TG2hpqe4ELx54QER/S3HQ9SRVnQnGBtKUz5bLQWtYAQ+o6GpgMs6sYUvaiJjVxb+UXwhRhAEP3m7LbsIZ77Hmw==
dependencies:
depd "~2.0.0"
keygrip "~1.1.0"
Expand Down Expand Up @@ -7474,6 +7490,11 @@ infer-owner@^1.0.4:
resolved "https://registry.yarnpkg.com/infer-owner/-/infer-owner-1.0.4.tgz#c4cefcaa8e51051c2a40ba2ce8a3d27295af9467"
integrity sha512-IClj+Xz94+d7irH5qRyfJonOdfTzuDaifE6ZPWfx0N0+/ATZCbuTPq2prFl526urkQd90WyUKIh1DfBQ2hMz9A==

inflation@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/inflation/-/inflation-2.1.0.tgz#9214db11a47e6f756d111c4f9df96971c60f886c"
integrity sha512-t54PPJHG1Pp7VQvxyVCJ9mBbjG3Hqryges9bXoOO6GExCPa+//i/d5GSuFtpx3ALLd7lgIAur6zrIlBQyJuMlQ==

inflight@^1.0.4:
version "1.0.6"
resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
Expand Down Expand Up @@ -8717,16 +8738,14 @@ koa-mount@^4.0.0:
debug "^4.0.1"
koa-compose "^4.1.0"

koa-router@^10.0.0:
version "10.1.1"
resolved "https://registry.yarnpkg.com/koa-router/-/koa-router-10.1.1.tgz#20809f82648518b84726cd445037813cd99f17ff"
integrity sha512-z/OzxVjf5NyuNO3t9nJpx7e1oR3FSBAauiwXtMQu4ppcnuNZzTaQ4p21P8A6r2Es8uJJM339oc4oVW+qX7SqnQ==
koa-router@^13.0.1:
version "13.0.1"
resolved "https://registry.yarnpkg.com/koa-router/-/koa-router-13.0.1.tgz#09607d35011960847b864231e3d502e28509866b"
integrity sha512-4/sijXdSxocIe2wv7RFFSxvo2ic1pDzPSmy11yCGztng1hx408qfw1wVmN3aqhQaU7U6nJ039JKC8ObE73Ohgw==
dependencies:
debug "^4.1.1"
http-errors "^1.7.3"
http-errors "^2.0.0"
koa-compose "^4.1.0"
methods "^1.1.2"
path-to-regexp "^6.1.0"
path-to-regexp "^8.1.0"

koa-send@^5.0.0, koa-send@^5.0.1:
version "5.0.1"
Expand All @@ -8745,7 +8764,7 @@ koa-static@^5.0.0:
debug "^3.1.0"
koa-send "^5.0.0"

koa-views@*:
koa-views@*, koa-views@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/koa-views/-/koa-views-8.1.0.tgz#d06d88140863b0fc35094b81d89558bb0077ce47"
integrity sha512-sIkZeplf7YKg1+OjYuzxU5zQvzbfdwFKzD8XNLKFHRMFZXWBTW+S/WQwQ32fzZiJp1lPxz0QlzNJkkGu0NVIdg==
Expand All @@ -8758,29 +8777,16 @@ koa-views@*:
pretty "^2.0.0"
resolve-path "^1.4.0"

koa-views@^7.0.1:
version "7.0.2"
resolved "https://registry.yarnpkg.com/koa-views/-/koa-views-7.0.2.tgz#c96fd9e2143ef00c29dc5160c5ed639891aa723d"
integrity sha512-dvx3mdVeSVuIPEaKAoGbxLcenudvhl821xxyuRbcoA+bOJ2dvN8wlGjkLu0ZFMlkCscXZV6lzxy28rafeazI/w==
dependencies:
consolidate "^0.16.0"
debug "^4.1.0"
get-paths "0.0.7"
koa-send "^5.0.0"
mz "^2.4.0"
pretty "^2.0.0"
resolve-path "^1.4.0"

koa@^2.13.1:
version "2.14.2"
resolved "https://registry.yarnpkg.com/koa/-/koa-2.14.2.tgz#a57f925c03931c2b4d94b19d2ebf76d3244863fc"
integrity sha512-VFI2bpJaodz6P7x2uyLiX6RLYpZmOJqNmoCst/Yyd7hQlszyPwG/I9CQJ63nOtKSxpt5M7NH67V6nJL2BwCl7g==
koa@^2.15.3:
version "2.15.3"
resolved "https://registry.yarnpkg.com/koa/-/koa-2.15.3.tgz#062809266ee75ce0c75f6510a005b0e38f8c519a"
integrity sha512-j/8tY9j5t+GVMLeioLaxweJiKUayFhlGqNTzf2ZGwL0ZCQijd2RLHK0SLW5Tsko8YyyqCZC2cojIb0/s62qTAg==
dependencies:
accepts "^1.3.5"
cache-content-type "^1.0.0"
content-disposition "~0.5.2"
content-type "^1.0.4"
cookies "~0.8.0"
cookies "~0.9.0"
debug "^4.3.2"
delegates "^1.0.0"
depd "^2.0.0"
Expand Down Expand Up @@ -9568,7 +9574,7 @@ mute-stream@1.0.0:
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-1.0.0.tgz#e31bd9fe62f0aed23520aa4324ea6671531e013e"
integrity sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==

mz@^2.4.0, mz@^2.7.0:
mz@^2.7.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/mz/-/mz-2.7.0.tgz#95008057a56cafadc2bc63dde7f9ff6955948e32"
integrity sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==
Expand Down Expand Up @@ -10402,10 +10408,10 @@ path-to-regexp@^1.7.0:
dependencies:
isarray "0.0.1"

path-to-regexp@^6.1.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-6.2.1.tgz#d54934d6798eb9e5ef14e7af7962c945906918e5"
integrity sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw==
path-to-regexp@^8.1.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-8.2.0.tgz#73990cc29e57a3ff2a0d914095156df5db79e8b4"
integrity sha512-TdrF7fW9Rphjq4RjrW0Kp2AW0Ahwu9sRGTkS6bvDi0SCwZlEZYmcfDbEsTz8RVk0EHIS/Vd1bv3JhG+1xZuAyQ==

path-type@^3.0.0:
version "3.0.0"
Expand Down Expand Up @@ -10706,7 +10712,7 @@ q@^1.5.1:
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
integrity sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw==

qs@6.13.0, qs@^6.11.0, qs@^6.9.4:
qs@6.13.0, qs@^6.11.0, qs@^6.5.2, qs@^6.9.4:
version "6.13.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.13.0.tgz#6ca3bd58439f7e245655798997787b0d88a51906"
integrity sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==
Expand Down Expand Up @@ -10778,7 +10784,7 @@ range-parser@~1.2.1:
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031"
integrity sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==

raw-body@2.5.2:
raw-body@2.5.2, raw-body@^2.3.3:
version "2.5.2"
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.5.2.tgz#99febd83b90e08975087e8f1f9419a149366b68a"
integrity sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==
Expand Down Expand Up @@ -12543,7 +12549,7 @@ type-fest@^2.13.0, type-fest@^2.5.1:
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.19.0.tgz#88068015bb33036a598b952e55e9311a60fd3a9b"
integrity sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==

type-is@^1.6.16, type-is@~1.6.18:
type-is@^1.6.16, type-is@^1.6.18, type-is@~1.6.18:
version "1.6.18"
resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131"
integrity sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==
Expand Down

0 comments on commit 60952e8

Please sign in to comment.