diff --git a/packages/server/src/api/index.js b/packages/server/src/api/index.js index f5a23bbede..2b26b8e783 100644 --- a/packages/server/src/api/index.js +++ b/packages/server/src/api/index.js @@ -7,13 +7,6 @@ const { mainRoutes, staticRoutes } = require("./routes") const pkg = require("../../package.json") const env = require("../environment") -if (!env.isTest()) { - const bullboard = require("bull-board") - const expressApp = require("express")() - - expressApp.use("/bulladmin", bullboard.router) -} - const router = new Router() router diff --git a/packages/server/src/app.js b/packages/server/src/app.js index d7b20a0613..b39b76b405 100644 --- a/packages/server/src/app.js +++ b/packages/server/src/app.js @@ -12,6 +12,7 @@ const eventEmitter = require("./events") const automations = require("./automations/index") const Sentry = require("@sentry/node") const fileSystem = require("./utilities/fileSystem") +const bullboard = require("./automations/bullboard") const app = new Koa() @@ -35,6 +36,19 @@ app.use( }) ) +if (!env.isTest()) { + const bullApp = bullboard.init() + app.use(async (ctx, next) => { + if (ctx.path.startsWith(bullboard.pathPrefix)) { + ctx.status = 200 + ctx.respond = false + bullApp(ctx.req, ctx.res) + } else { + await next() + } + }) +} + app.context.eventEmitter = eventEmitter app.context.auth = {} @@ -55,6 +69,7 @@ if (env.isProd()) { }) } + const server = http.createServer(app.callback()) destroyable(server) diff --git a/packages/server/src/automations/bullboard.js b/packages/server/src/automations/bullboard.js new file mode 100644 index 0000000000..ac073bee79 --- /dev/null +++ b/packages/server/src/automations/bullboard.js @@ -0,0 +1,20 @@ +const { createBullBoard } = require("bull-board") +const { BullAdapter } = require("bull-board/bullAdapter") +const { getQueues } = require("./triggers") +const express = require("express") + +exports.pathPrefix = "/bulladmin" + +exports.init = () => { + const expressApp = express() + // Set up queues for bull board admin + const queues = getQueues() + const adapters = [] + for (let queue of queues) { + adapters.push(new BullAdapter(queue)) + } + const { router } = createBullBoard(adapters) + + expressApp.use(exports.pathPrefix, router) + return expressApp +} \ No newline at end of file diff --git a/packages/server/src/automations/triggers.js b/packages/server/src/automations/triggers.js index ca5e90ed14..4faf588edc 100644 --- a/packages/server/src/automations/triggers.js +++ b/packages/server/src/automations/triggers.js @@ -4,7 +4,6 @@ const env = require("../environment") const Queue = env.isTest() ? require("../utilities/queue/inMemoryQueue") : require("bull") -const { setQueues, BullAdapter } = require("bull-board") const { getAutomationParams } = require("../db/utils") const { coerce } = require("../utilities/rowProcessor") const { utils } = require("@budibase/auth").redis @@ -12,9 +11,6 @@ const { utils } = require("@budibase/auth").redis const { opts } = utils.getRedisOptions() let automationQueue = new Queue("automationQueue", { redis: opts }) -// Set up queues for bull board admin -setQueues([new BullAdapter(automationQueue)]) - const FAKE_STRING = "TEST" const FAKE_BOOL = false const FAKE_NUMBER = 1 @@ -310,6 +306,9 @@ module.exports.externalTrigger = async function (automation, params) { automationQueue.add({ automation, event: params }) } +module.exports.getQueues = () => { + return [ automationQueue ] +} module.exports.fillRowOutput = fillRowOutput module.exports.automationQueue = automationQueue