about summary refs log tree commit diff
path: root/bskylink/src/routes/health.ts
blob: c8a30c59eab28408f4146f8e4710e12d3d5bb55b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import {Express} from 'express'
import {sql} from 'kysely'

import {AppContext} from '../context.js'
import {handler} from './util.js'

export default function (ctx: AppContext, app: Express) {
  return app.get(
    '/_health',
    handler(async (_req, res) => {
      const {version} = ctx.cfg.service
      try {
        await sql`select 1`.execute(ctx.db.db)
        return res.send({version})
      } catch (err) {
        return res.status(503).send({version, error: 'Service Unavailable'})
      }
    }),
  )
}