Merge pull request #12565 from Budibase/fix/health-check-with-app-features

Allowing healthcheck when in automation only mode (app service)
This commit is contained in:
Michael Drury 2023-12-13 11:44:38 +00:00 committed by GitHub
commit 935e63104c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 59 deletions

View File

@ -4,6 +4,7 @@ import currentApp from "../middleware/currentapp"
import zlib from "zlib"
import { mainRoutes, staticRoutes, publicRoutes } from "./routes"
import { middleware as pro } from "@budibase/pro"
import { apiEnabled } from "../features"
import migrations from "../middleware/appMigrations"
export { shutdown } from "./routes/public"
@ -16,7 +17,9 @@ router.get("/version", ctx => (ctx.body = envCore.VERSION))
router.use(middleware.errorHandling)
router
// only add the routes if they are enabled
if (apiEnabled()) {
router
.use(
compress({
threshold: 2048,
@ -51,15 +54,16 @@ router
// @ts-ignore
.use(migrations)
// authenticated routes
for (let route of mainRoutes) {
// authenticated routes
for (let route of mainRoutes) {
router.use(route.routes())
router.use(route.allowedMethods())
}
router.use(publicRoutes.routes())
router.use(publicRoutes.allowedMethods())
// WARNING - static routes will catch everything else after them this must be last
router.use(staticRoutes.routes())
router.use(staticRoutes.allowedMethods())
}
router.use(publicRoutes.routes())
router.use(publicRoutes.allowedMethods())
// WARNING - static routes will catch everything else after them this must be last
router.use(staticRoutes.routes())
router.use(staticRoutes.allowedMethods())

View File

@ -9,7 +9,6 @@ import { ServiceType } from "@budibase/types"
import { env as coreEnv } from "@budibase/backend-core"
coreEnv._set("SERVICE_TYPE", ServiceType.APPS)
import { apiEnabled } from "./features"
import createKoaApp from "./koa"
import Koa from "koa"
import { Server } from "http"
@ -18,12 +17,9 @@ import { startup } from "./startup"
let app: Koa, server: Server
async function start() {
// if API disabled, could run automations instead
if (apiEnabled()) {
const koa = createKoaApp()
app = koa.app
server = koa.server
}
// startup includes automation runner - if enabled
await startup(app, server)
}

View File

@ -22,3 +22,10 @@ export function automationsEnabled() {
export function apiEnabled() {
return featureList.includes(AppFeature.API)
}
export function printFeatures() {
if (!env.APP_FEATURES) {
return
}
console.log(`**** APP FEATURES SET: ${featureList.join(", ")} ****`)
}

View File

@ -19,11 +19,14 @@ import * as pro from "@budibase/pro"
import * as api from "./api"
import sdk from "./sdk"
import { initialise as initialiseWebsockets } from "./websockets"
import { automationsEnabled } from "./features"
import { automationsEnabled, printFeatures } from "./features"
import Koa from "koa"
import { Server } from "http"
import { AddressInfo } from "net"
let STARTUP_RAN = false
async function initRoutes(app: any) {
async function initRoutes(app: Koa) {
if (!env.isTest()) {
const plugin = await bullboard.init()
app.use(plugin)
@ -48,27 +51,31 @@ async function initPro() {
})
}
function shutdown(server?: any) {
function shutdown(server?: Server) {
if (server) {
server.close()
server.destroy()
}
}
export async function startup(app?: any, server?: any) {
export async function startup(app?: Koa, server?: Server) {
if (STARTUP_RAN) {
return
}
printFeatures()
STARTUP_RAN = true
if (server && !env.CLUSTER_MODE) {
if (app && server && !env.CLUSTER_MODE) {
console.log(`Budibase running on ${JSON.stringify(server.address())}`)
env._set("PORT", server.address().port)
const address = server.address() as AddressInfo
env._set("PORT", address.port)
}
eventEmitter.emitPort(env.PORT)
fileSystem.init()
await redis.init()
eventInit()
if (app && server) {
initialiseWebsockets(app, server)
}
// run migrations on startup if not done via http
// not recommended in a clustered environment