bull-board: V3 not working with NestJS
I’m running into an issue where is appears the serverAdapter isn’t handling req as expected — I just simply get a 404. I setup a basic example Stackblitz => https://stackblitz.com/edit/nestjs-starter-demo-gvfxkh
I was using v1.5.1 before - here is was my working main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { router } from 'bull-board';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.use('/admin/queues', router);
await app.listen(3000);
}
bootstrap();
I migrated to v3.3.0 yesterday and have no very little luck with getting ExpressAdapter
working correctly. Here is my current non-working main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ExpressAdapter } from '@bull-board/express';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const serverAdapter = new ExpressAdapter();
serverAdapter.setBasePath('/admin/queues');
app.use('/admin/queues', serverAdapter.getRouter());
await app.listen(3000);
}
bootstrap();
Any help would be awesome!
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 33 (21 by maintainers)
This should work too.
I couldn’t get the above examples to work with my setup, so I thought I’d paste what I got to work in case anyone else is in the same boat.
My versions:
My Controller:
And the relevant part of
QueuesManagerService
, which initializes bull-board. Note thatinitBullBoard
is called as part ofonModuleInit
:The odd thing is that
serverAdapter
is told the base path, and prefixes all the client requests with the base path, as appropriate. However, the express router that it returns does not use the given prefix to set its routes. Without thereq.url = req.url.replace(entryPointPath, '/');
line, I was getting 404s since the router didn’t match the path - it needs ‘/’ instead of ‘/api/queues/admin/’.@felixmosh finally got some time to flush this out, let me know what you think.
main.ts
I get my queue pool and loop over it and calladdQueue
I just import my class and add my queue pool =>
queuePool.add(updateQueue)
— not perfect but gets the job done. Thanks for the help!I used @asomethings’s solution and added a BasicAuth middleware. My goal was to have everything related to queues in a single module and not spread out in main/bootstrap.ts.
This is the reason that I’ve asked, since I’m not familiar with Nest.js ecosystem :]
Thanks for the feedback!
For the first one, i’ll update the example on how to do that! For the second one, at the moment the ExpressAdapter is hardcoded, however… NestJS only supports Express and Fastify, since you also have a Fastify adapter available, i’ll take a look into supporting Fastify. Thanks!
edit: I updated the example repository with a “feature controller” whichs is getting the “BullBoardInstance” injected for usage.
If you have multiple queues and the queue registration is spread throughout your app, you can do something like this: Global BullQueueModule with 1 service:
BullQueueService:
Modules that add their queues to bull queue service:
I spend the day trying to ‘share’ addQueue from main.ts to my queueService. A good solution was to use the HttpAdapterHost of my AppModule