Skip to content

Commit

Permalink
added bull-board with basic authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
omranjamal committed Oct 4, 2024
1 parent 427bbd6 commit 09b04c9
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 4 deletions.
5 changes: 4 additions & 1 deletion apps/jonogon-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
"universal-base64url": "^1.1.0",
"winston": "3.14.0",
"ws": "8.18.0",
"zod": "3.23.8"
"zod": "3.23.8",
"@bull-board/express": "6.0.0",
"@bull-board/api": "6.0.0",
"express-basic-auth": "1.2.1"
},
"devDependencies": {
"@types/cors": "2.8.17",
Expand Down
36 changes: 36 additions & 0 deletions apps/jonogon-core/src/api/http/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import {appRouter} from '../trpc/routers/index.mjs';
import {env} from '../../env.mjs';
import {createProfilePictureHandler} from './handlers/users/picture.mjs';
import {createPetitionAttachmentHandler} from './handlers/petitions/attachment.mjs';
import {ExpressAdapter} from '@bull-board/express';
import {BullAdapter} from '@bull-board/api/bullAdapter.js';
import {createBullBoard} from '@bull-board/api';
import {milestoneDetectionQueue} from '../../services/queues/milestoneDetectionQueue.mjs';
import {notificationsSchedulerQueue} from '../../services/queues/notificationsSchedulerQueue.mjs';
import {smsNotificationDispatchQueue} from '../../services/queues/smsNotificationDispatchQueue.mjs';
import basicAuth from 'express-basic-auth';

export async function registerHTTPRoutes(
expressApp: Express,
Expand Down Expand Up @@ -58,4 +65,33 @@ export async function registerHTTPRoutes(
}),
);
}

const bullBoardPath = '/queues';

const bullExpressAdapter = new ExpressAdapter();
bullExpressAdapter.setBasePath(bullBoardPath);

const {} = createBullBoard({
queues: [
new BullAdapter(milestoneDetectionQueue),
new BullAdapter(notificationsSchedulerQueue),
new BullAdapter(smsNotificationDispatchQueue),
],
serverAdapter: bullExpressAdapter,
});

if (env.BULL_BOARD_USERNAME && env.BULL_BOARD_PASSWORD) {
app.use(
bullBoardPath,
basicAuth({
users: {
[env.BULL_BOARD_USERNAME]: env.BULL_BOARD_PASSWORD,
},
challenge: true,
}),
bullExpressAdapter.getRouter(),
);
} else if (env.NODE_ENV === 'development') {
app.use(bullBoardPath, bullExpressAdapter.getRouter());
}
}
3 changes: 3 additions & 0 deletions apps/jonogon-core/src/env.mts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export const env = createEnv({

COMMON_HMAC_SECRET: z.string(),
COMMON_ENCRYPTION_SECRET: z.string(),

BULL_BOARD_USERNAME: z.string().optional(),
BULL_BOARD_PASSWORD: z.string().optional(),
},
runtimeEnv: process.env,
});
107 changes: 104 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 09b04c9

Please sign in to comment.