Merge branch 'master' of github.com:budibase/budibase into ops-228-split-out-automations-from-main-app-infrastructure
This commit is contained in:
commit
810f369f88
|
@ -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"
|
||||
import { automationsEnabled } from "../features"
|
||||
import { automationQueue } from "../automations"
|
||||
|
@ -26,6 +27,8 @@ router.get("/version", ctx => (ctx.body = envCore.VERSION))
|
|||
|
||||
router.use(middleware.errorHandling)
|
||||
|
||||
// only add the routes if they are enabled
|
||||
if (apiEnabled()) {
|
||||
router
|
||||
.use(
|
||||
compress({
|
||||
|
@ -73,3 +76,4 @@ 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())
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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(", ")} ****`)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue