about summary refs log tree commit diff
path: root/bskylink/src/routes/health.ts
diff options
context:
space:
mode:
Diffstat (limited to 'bskylink/src/routes/health.ts')
-rw-r--r--bskylink/src/routes/health.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/bskylink/src/routes/health.ts b/bskylink/src/routes/health.ts
new file mode 100644
index 000000000..c8a30c59e
--- /dev/null
+++ b/bskylink/src/routes/health.ts
@@ -0,0 +1,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'})
+      }
+    }),
+  )
+}