diff --git a/server/src/expressHandler.ts b/server/src/expressHandler.ts index 2dde4c22..425cc9d0 100644 --- a/server/src/expressHandler.ts +++ b/server/src/expressHandler.ts @@ -14,6 +14,10 @@ const staticPath = path.join( 'dist' ) logger.data(staticPath).debug('Express static file path:') + +import { setupHealthEndpoint } from './nrk/health' +setupHealthEndpoint(app) + app.use('/', express.static(staticPath)) server.listen(SERVER_PORT) logger.info(`Server started at http://localhost:${SERVER_PORT}`) diff --git a/server/src/nrk/health.ts b/server/src/nrk/health.ts new file mode 100644 index 00000000..74243cfd --- /dev/null +++ b/server/src/nrk/health.ts @@ -0,0 +1,64 @@ +import { Express } from 'express' +import { state } from '../reducers/store' + +/** + * Health report as described in internal NRK blaabok spec + */ +interface HealthReport { + /** Overordnet status på det kjørende systemet. Se Registrerte Definerte Verdier STATUS. */ + status: Status + /** Navn på det kjørende systemet (Må være statisk! dvs ikke inneholde data om feks timings el.). */ + name: string + /** Tidspunkt for når innholdet i rapporten ble oppdatert eller rapporten ble generert. Format: Timestamps. */ + updated: string + /** Hvor finner du dokumentasjonen til systemet. */ + documentation: string + /** Hvilken version av helsesjekk standard er implementert. */ + version: '5' + + // internal fields (not according to spec, but sofie uses these): + _internal: { + // statusCode: StatusCode, + statusCodeString: string + messages: Array + versions: { [component: string]: string } + } +} +enum Status { + OK = 'OK', + Warning = 'WARNING', + Fail = 'FAIL', + Undefined = 'UNDEFINED', +} + +export function setupHealthEndpoint(app: Express) { + app.get('/health', (req, res) => { + const health: HealthReport = { + status: Status.OK, + name: 'Sisyfos', + updated: new Date().toISOString(), + documentation: + 'https://github.com/nrkno/sofie-sisyfos-audio-controller', + version: '5', + _internal: { + statusCodeString: 'OK', + messages: [], + versions: { + sisyfos: process.env.npm_package_version, + }, + }, + } + + const isOnline = state.settings[0].serverOnline + if (!isOnline) { + health.status = Status.Warning + health._internal.statusCodeString = 'WARNING' + health._internal.messages.push('Mixer disconnected') + } + + res.json(health) + res.status(200) + res.end() + }) +} +