Skip to content
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

Problems with NX and NestJS in Production #347

Closed
henrysachs opened this issue Nov 30, 2021 · 9 comments
Closed

Problems with NX and NestJS in Production #347

henrysachs opened this issue Nov 30, 2021 · 9 comments

Comments

@henrysachs
Copy link

henrysachs commented Nov 30, 2021

Hey There I've integrated bull-board with nestjs and I'm using nx to manage my monorepo. I got this working locally with a NestJS Middlleware implementing Bull-Board and everthing seems fine. This is my Middleware:

import { createBullBoard } from '@bull-board/api';
import { BullAdapter } from '@bull-board/api/bullAdapter';
import { ExpressAdapter } from '@bull-board/express';
import { Injectable, NestMiddleware } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import * as Queue from 'bull';
import { NextFunction, Request, Response } from 'express';

@Injectable()
export class BullBoardMiddleware implements NestMiddleware {
  serverAdapter;

  constructor(private configService: ConfigService) {
    this.serverAdapter = new ExpressAdapter();
    createBullBoard({
      queues: [new BullAdapter(new Queue('scan_secrets'), { readOnlyMode: true })],
      serverAdapter: this.serverAdapter
    });
    this.serverAdapter.setBasePath('/api/queues');
  }

  use(req: Request, res: Response, next: NextFunction) {
    if (this.serverAdapter) {
      const router = this.serverAdapter.getRouter();
      try {
        return router(req, res, next);
      } catch (e) {
        console.log('BULL-BOARD: Some error occured', e);
        res.send('Error');
      }
    }
    next();
  }
}

But as soon as i'm deploying it to a Docker container the Api routes dont seem to register anymore i get the UI and so on but its Stuck on loading...

when opening the network tab i see requests unanswered and timing out.

these point to https://MYDOMAIN/api/queues/api/queues?page=1
until then i noticed a bit of a weird path scheme but this works locally.

Any Idea how i could debug this further?


version: "@bull-board/express": "^3.7.0",

@felixmosh
Copy link
Owner

Try to setup your bull-board like it was setup in here:
#303 (comment)

@henrysachs
Copy link
Author

i still receive the same error.

@felixmosh
Copy link
Owner

Show some code pls :]

@henrysachs
Copy link
Author

async function bootstrap() {
  const app = await NestFactory.create(AppModule, { bufferLogs: true });
  app.connectMicroservice({
    transport: Transport.GRPC,
    options: {
      package: 'grs',
      protoPath: join(__dirname, 'grs/grs.proto'),
      loader: { keepCase: true },
      url: '0.0.0.0:50051'
    }
  });
  const globalPrefix = 'api';
  app.setGlobalPrefix(globalPrefix);
  const port = process.env.PORT || 3333;
  const logger = app.get<OgmaService>(OgmaService);

  app.useLogger(logger);
  app.enableShutdownHooks();
  app.enableCors({ origin: '*' });

  app.use(passport.initialize());

  const serverAdapter = new ExpressAdapter();
  serverAdapter.setBasePath('/admin/queues');

  createBullBoard({
    queues: [new BullAdapter(new Queue('scan_secrets'), { readOnlyMode: true })],
    serverAdapter
  });

  app.use('/admin/queues', serverAdapter.getRouter());

  const config = new DocumentBuilder()
    .setTitle('GRS Api')
    .setDescription('The Api for the main GRS component')
    .setVersion('1.0')
    .addBearerAuth()
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup(globalPrefix + '/swagger', app, document, {
    swaggerOptions: {
      persistAuthorization: true
    },
    customSiteTitle: 'Grs Api Docs'
  });

  await app.startAllMicroservices();
  await app.listen(port, '0.0.0.0', () => {
    logger.log('Listening at http://localhost:' + port + '/' + globalPrefix);
  });
}

But I think it could also be Loadbalancer related.

@felixmosh
Copy link
Owner

The setup of bull-board looks OK to me.

@henrysachs
Copy link
Author

What is weird for me is that the webui is loading but is stuck at 'loading...' because the api requests wont be served.

@felixmosh
Copy link
Owner

what do you see in the console?

@pnlinh-it
Copy link

@henrysachs I face that issue. Use

 serverAdapter.setBasePath('/api/admin/queues');

instead of

 serverAdapter.setBasePath('/admin/queues');

@felixmosh
Copy link
Owner

I'm closing it since it is not active, reopen if the issue doesn't solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants