Skip to content

Commit

Permalink
feat: [NestJS] Fastify global prefix support (#704)
Browse files Browse the repository at this point in the history
* fix: Prefix requires a leading forward slash to load static folder correctly

* feat: Replace String.replace with addForwardSlash function
  • Loading branch information
dimbslmh authored Mar 24, 2024
1 parent 626f9a0 commit 04f07b2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/nestjs/src/bull-board.root-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ export class BullBoardRootModule implements NestModule {
}

configure(consumer: MiddlewareConsumer): any {
const globalPrefix = this.applicationConfig.getGlobalPrefix() || '';
this.adapter.setBasePath(`${ globalPrefix }${ this.options.route }`);
const addForwardSlash = (path: string) => {
return path.startsWith('/') || path === '' ? path : `/${path}`;
};
const prefix = addForwardSlash(this.applicationConfig.getGlobalPrefix() + this.options.route);

this.adapter.setBasePath(prefix);

if (isExpressAdapter(this.adapter)) {
return consumer
Expand All @@ -29,9 +33,9 @@ export class BullBoardRootModule implements NestModule {
if (isFastifyAdapter(this.adapter)) {
this.adapterHost.httpAdapter
.getInstance()
.register(this.adapter.registerPlugin(), {prefix: this.options.route});
.register(this.adapter.registerPlugin(), { prefix });

return consumer
return consumer
.apply(this.options.middleware)
.forRoutes(this.options.route);
}
Expand Down

0 comments on commit 04f07b2

Please sign in to comment.