-
-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use it in koa2? #29
Comments
hey @ltjin! thank's for the issue! I didn't really consider this possibility 😅so maybe there are some gotchas on how would this be setup. |
Hi, This worked for me, with Koa router:
EDIT: use |
@roparz yes, that's right. const router = require('koa-router')();
const { UI } = require('bull-board');
router.prefix('/monitor');
router.all('*', async (ctx, next) => {
if (ctx.status === 404 || ctx.status === '404') {
delete ctx.res.statusCode
}
ctx.respond = false;
const app = UI('/monitor'); // add routing prefix to express app
app(ctx.req, ctx.res);
});
module.exports = router; and bull-board/index.js const Queue = require('bull')
const express = require('express')
const bodyParser = require('body-parser')
const router = require('express-async-router').AsyncRouter()
const path = require('path')
const queues = {}
function UI(prefix) { // add routing prefix to express app
const app = express()
app.locals.queues = queues
app.set('view engine', 'ejs')
app.set('views', `${__dirname}/ui`);
router.use('/static', express.static(path.join(__dirname, './static')))
router.get('/queues', require('./routes/queues'))
router.put('/queues/:queueName/retry', require('./routes/retryAll'))
router.put('/queues/:queueName/:id/retry', require('./routes/retryJob'))
router.put('/queues/:queueName/clean', require('./routes/cleanAll'))
router.get('/', require('./routes/index'))
app.use(bodyParser.json())
if(prefix){ // add routing prefix to express app
app.use(prefix, router)
}else{
app.use(router)
}
return app
}
module.exports = {
UI: UI, // return UI
createQueues: redis => {
return {
add: (name, opts) => {
const queue = new Queue(name, redis, opts)
queues[name] = queue
return queue
}
}
},
get: ()=>{
return queues;
}
} This way makes intrusive changes to the source code, I'm not sure if I should submit a PR |
You make me point out that my solution only works on GET requests... |
The core of this problem is that the request link forwarded by Koa does not have a corresponding route in the expressAPP inside the bull-board. |
Hey folks, nice that you took the time to think about a solution, I really appreciate it since I didn’t have the time to look into it so far 😅 Please feel free to open a PR, I’ll review it properly and as long as we don’t introduce breaking changes I guess it's fine 👍 |
Has anyone solved this with recent versions of |
Since PR's are always welcome. |
@felixmosh I cannot install |
Pay attention to the fact that we started to release under @bull-board scope ;) |
Oh, I didn't notice that. Thanks. |
I want to use it in an application built by koa2,but I don't get it.
my code like:
This is from Can we mount express app into koa?
The text was updated successfully, but these errors were encountered: