Fixing issues with bullboard and integrating the express app with our koa app (if prefix matches).
This commit is contained in:
parent
7e10dc16b3
commit
ad02e56887
|
@ -7,13 +7,6 @@ const { mainRoutes, staticRoutes } = require("./routes")
|
||||||
const pkg = require("../../package.json")
|
const pkg = require("../../package.json")
|
||||||
const env = require("../environment")
|
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()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
|
|
|
@ -12,6 +12,7 @@ const eventEmitter = require("./events")
|
||||||
const automations = require("./automations/index")
|
const automations = require("./automations/index")
|
||||||
const Sentry = require("@sentry/node")
|
const Sentry = require("@sentry/node")
|
||||||
const fileSystem = require("./utilities/fileSystem")
|
const fileSystem = require("./utilities/fileSystem")
|
||||||
|
const bullboard = require("./automations/bullboard")
|
||||||
|
|
||||||
const app = new Koa()
|
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.eventEmitter = eventEmitter
|
||||||
app.context.auth = {}
|
app.context.auth = {}
|
||||||
|
|
||||||
|
@ -55,6 +69,7 @@ if (env.isProd()) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const server = http.createServer(app.callback())
|
const server = http.createServer(app.callback())
|
||||||
destroyable(server)
|
destroyable(server)
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -4,7 +4,6 @@ const env = require("../environment")
|
||||||
const Queue = env.isTest()
|
const Queue = env.isTest()
|
||||||
? require("../utilities/queue/inMemoryQueue")
|
? require("../utilities/queue/inMemoryQueue")
|
||||||
: require("bull")
|
: require("bull")
|
||||||
const { setQueues, BullAdapter } = require("bull-board")
|
|
||||||
const { getAutomationParams } = require("../db/utils")
|
const { getAutomationParams } = require("../db/utils")
|
||||||
const { coerce } = require("../utilities/rowProcessor")
|
const { coerce } = require("../utilities/rowProcessor")
|
||||||
const { utils } = require("@budibase/auth").redis
|
const { utils } = require("@budibase/auth").redis
|
||||||
|
@ -12,9 +11,6 @@ const { utils } = require("@budibase/auth").redis
|
||||||
const { opts } = utils.getRedisOptions()
|
const { opts } = utils.getRedisOptions()
|
||||||
let automationQueue = new Queue("automationQueue", { redis: opts })
|
let automationQueue = new Queue("automationQueue", { redis: opts })
|
||||||
|
|
||||||
// Set up queues for bull board admin
|
|
||||||
setQueues([new BullAdapter(automationQueue)])
|
|
||||||
|
|
||||||
const FAKE_STRING = "TEST"
|
const FAKE_STRING = "TEST"
|
||||||
const FAKE_BOOL = false
|
const FAKE_BOOL = false
|
||||||
const FAKE_NUMBER = 1
|
const FAKE_NUMBER = 1
|
||||||
|
@ -310,6 +306,9 @@ module.exports.externalTrigger = async function (automation, params) {
|
||||||
automationQueue.add({ automation, event: params })
|
automationQueue.add({ automation, event: params })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.getQueues = () => {
|
||||||
|
return [ automationQueue ]
|
||||||
|
}
|
||||||
module.exports.fillRowOutput = fillRowOutput
|
module.exports.fillRowOutput = fillRowOutput
|
||||||
module.exports.automationQueue = automationQueue
|
module.exports.automationQueue = automationQueue
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue