Skip to content

Commit

Permalink
fix bull board
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan0005 committed Oct 6, 2024
1 parent bf64c76 commit 7b6fbe2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
21 changes: 18 additions & 3 deletions apps/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import * as cluster from 'cluster';
import events from 'events';
import * as express from 'express';
import { NextFunction, Request, Response } from 'express';
import basicAuth from 'express-basic-auth';
import helmet from 'helmet';
import { WinstonModule } from 'nest-winston';
Expand Down Expand Up @@ -111,8 +112,22 @@ async function bootstrap() {
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup(routePrefix + '/swagger', app, document);

// Apply Helmet for security (e.g., XSS prevention, frameguard, HSTS)
// Set up basic authentication for accessing compiler queues
app.use(
['/' + routePrefix + '/queues'],
basicAuth({
users: { developer: serverSecret },
challenge: true,
realm: 'Bull Board'
})
);

// Apply Helmet for security (e.g., XSS prevention, frameguard, HSTS)
app.use((req: Request, res: Response, next: NextFunction) => {
if (req.path === '/' + routePrefix + '/queues') {
return next(); // Skip Helmet for /queues
}

helmet({
contentSecurityPolicy: {
useDefaults: true,
Expand Down Expand Up @@ -141,8 +156,8 @@ async function bootstrap() {
referrerPolicy: { policy: 'same-origin' },
crossOriginEmbedderPolicy: true,
crossOriginOpenerPolicy: { policy: 'same-origin' }
})
);
})(req, res, next); // Apply Helmet middleware
});

// Enable graceful shutdown with NestJS built-in hooks
app.enableShutdownHooks();
Expand Down
21 changes: 2 additions & 19 deletions apps/backend/src/modules/compiler/compiler.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { ExpressAdapter } from '@bull-board/express';
import { BullBoardModule } from '@bull-board/nestjs';
import { InjectionType } from '@full-stack-project/shared';
import { BullModule } from '@nestjs/bullmq';
import { MiddlewareConsumer, Module } from '@nestjs/common';
import { Module } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import basicAuth from 'express-basic-auth';
import { CompileController } from './controllers';
import { CompileQueueService, CompileService } from './services';

Expand Down Expand Up @@ -41,20 +40,4 @@ import { CompileQueueService, CompileService } from './services';
CompileQueueService
]
})
export class CompilerModule {
constructor(private readonly configService: ConfigService) {}

configure(consumer: MiddlewareConsumer) {
const serverSecret: string = this.configService.get('server.secret') as string;

consumer
.apply(
basicAuth({
users: { developer: serverSecret },
challenge: true,
realm: 'Bull Board'
})
)
.forRoutes('/queues');
}
}
export class CompilerModule {}

0 comments on commit 7b6fbe2

Please sign in to comment.