Skip to content

Commit

Permalink
Merge pull request #14 from nrkno/feat/health-endpoint
Browse files Browse the repository at this point in the history
feat: NRK health endpoint
  • Loading branch information
mint-dewit authored Dec 6, 2023
2 parents ff3e071 + 2b702ec commit 7050530
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
4 changes: 4 additions & 0 deletions server/src/expressHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
64 changes: 64 additions & 0 deletions server/src/nrk/health.ts
Original file line number Diff line number Diff line change
@@ -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<string>
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()
})
}

0 comments on commit 7050530

Please sign in to comment.