Fixing issues with bullboard and integrating the express app with our koa app (if prefix matches).

This commit is contained in:
mike12345567 2021-05-07 12:24:51 +01:00
parent 7e10dc16b3
commit ad02e56887
4 changed files with 38 additions and 11 deletions

View File

@ -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

View File

@ -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)

View File

@ -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
}

View File

@ -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