feat: Add http basic auth for BullMQ dashboard
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
"discord.js": "13.2.0",
|
||||
"dotenv": "^10.0.0",
|
||||
"express": "~4.16.1",
|
||||
"express-basic-auth": "^1.2.1",
|
||||
"express-graphql": "^0.12.0",
|
||||
"fast-xml-parser": "^4.0.11",
|
||||
"flickr-sdk": "3.10.0",
|
||||
|
@@ -1,4 +1,3 @@
|
||||
import appConfig from './config/app';
|
||||
import createError from 'http-errors';
|
||||
import express, { Request, Response, NextFunction } from 'express';
|
||||
import cors from 'cors';
|
||||
@@ -15,15 +14,11 @@ import {
|
||||
} from './helpers/create-bull-board-handler';
|
||||
import injectBullBoardHandler from './helpers/inject-bull-board-handler';
|
||||
|
||||
if (appConfig.enableBullMQDashboard) {
|
||||
createBullBoardHandler(serverAdapter);
|
||||
}
|
||||
createBullBoardHandler(serverAdapter);
|
||||
|
||||
const app = express();
|
||||
|
||||
if (appConfig.enableBullMQDashboard) {
|
||||
injectBullBoardHandler(app, serverAdapter);
|
||||
}
|
||||
injectBullBoardHandler(app, serverAdapter);
|
||||
|
||||
appAssetsHandler(app);
|
||||
|
||||
|
@@ -22,6 +22,8 @@ type AppConfig = {
|
||||
redisHost: string;
|
||||
redisPort: number;
|
||||
enableBullMQDashboard: boolean;
|
||||
bullMQDashboardUsername: string;
|
||||
bullMQDashboardPassword: string;
|
||||
telemetryEnabled: boolean;
|
||||
};
|
||||
|
||||
@@ -61,6 +63,8 @@ const appConfig: AppConfig = {
|
||||
redisPort: parseInt(process.env.REDIS_PORT || '6379'),
|
||||
enableBullMQDashboard:
|
||||
process.env.ENABLE_BULLMQ_DASHBOARD === 'true' ? true : false,
|
||||
bullMQDashboardUsername: process.env.BULLMQ_DASHBOARD_USERNAME,
|
||||
bullMQDashboardPassword: process.env.BULLMQ_DASHBOARD_PASSWORD,
|
||||
baseUrl,
|
||||
webAppUrl,
|
||||
telemetryEnabled: process.env.TELEMETRY_ENABLED === 'false' ? false : true,
|
||||
|
@@ -4,10 +4,18 @@ import { BullMQAdapter } from '@bull-board/api/bullMQAdapter';
|
||||
import flowQueue from '../queues/flow';
|
||||
import triggerQueue from '../queues/trigger';
|
||||
import actionQueue from '../queues/action';
|
||||
import appConfig from '../config/app';
|
||||
|
||||
const serverAdapter = new ExpressAdapter();
|
||||
|
||||
const createBullBoardHandler = async (serverAdapter: ExpressAdapter) => {
|
||||
if (
|
||||
!appConfig.enableBullMQDashboard ||
|
||||
!appConfig.bullMQDashboardUsername ||
|
||||
!appConfig.bullMQDashboardPassword
|
||||
)
|
||||
return;
|
||||
|
||||
createBullBoard({
|
||||
queues: [
|
||||
new BullMQAdapter(flowQueue),
|
||||
|
@@ -1,13 +1,32 @@
|
||||
import { Application } from 'express';
|
||||
import { ExpressAdapter } from '@bull-board/express';
|
||||
import basicAuth from 'express-basic-auth';
|
||||
import appConfig from '../config/app';
|
||||
|
||||
const injectBullBoardHandler = async (
|
||||
app: Application,
|
||||
serverAdapter: ExpressAdapter
|
||||
) => {
|
||||
if (
|
||||
!appConfig.enableBullMQDashboard ||
|
||||
!appConfig.bullMQDashboardUsername ||
|
||||
!appConfig.bullMQDashboardPassword
|
||||
)
|
||||
return;
|
||||
|
||||
const queueDashboardBasePath = '/admin/queues';
|
||||
serverAdapter.setBasePath(queueDashboardBasePath);
|
||||
app.use(queueDashboardBasePath, serverAdapter.getRouter());
|
||||
|
||||
app.use(
|
||||
queueDashboardBasePath,
|
||||
basicAuth({
|
||||
users: {
|
||||
[appConfig.bullMQDashboardUsername]: appConfig.bullMQDashboardPassword,
|
||||
},
|
||||
challenge: true,
|
||||
}),
|
||||
serverAdapter.getRouter()
|
||||
);
|
||||
};
|
||||
|
||||
export default injectBullBoardHandler;
|
||||
|
Reference in New Issue
Block a user