budibase/packages/server/src/app.ts

44 lines
1014 B
TypeScript
Raw Normal View History

import Sentry from "@sentry/node"
if (process.env.DD_APM_ENABLED) {
require("./ddApm")
}
// need to load environment first
import env from "./environment"
2022-11-26 16:10:41 +01:00
import * as db from "./db"
db.init()
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"
import { startup } from "./startup"
2020-07-16 15:27:27 +02:00
let app: Koa, server: Server
2023-02-04 19:51:10 +01:00
async function start() {
2023-08-21 16:31:35 +02:00
// if API disabled, could run automations instead
if (apiEnabled()) {
const koa = createKoaApp()
app = koa.app
server = koa.server
2023-02-04 21:30:12 +01:00
}
2023-08-21 16:31:35 +02:00
// startup includes automation runner - if enabled
2023-01-31 17:15:11 +01:00
await startup(app, server)
if (env.isProd()) {
env._set("NODE_ENV", "production")
Sentry.init()
}
}
start().catch(err => {
console.error(`Failed server startup - ${err.message}`)
})
2022-08-31 11:47:41 +02:00
export function getServer() {
2023-08-17 17:51:11 +02:00
return server
}