diff --git a/Dockerfile b/Dockerfile index 0c6cc62..5130891 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,7 @@ USER bun ENV PORT=3000 HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \ - CMD bun -e "fetch(\`http://localhost:\${process.env.PORT}\`).then(r=>{if(!r.ok)throw 1}).catch(()=>process.exit(1))" + CMD bun -e "fetch(\`http://localhost:\${process.env.PORT}/health\`).then(r=>{if(!r.ok)throw 1}).catch(()=>process.exit(1))" EXPOSE 3000 CMD ["bun", "run", "start"] diff --git a/server.ts b/server.ts index 70ef218..efc667a 100644 --- a/server.ts +++ b/server.ts @@ -1,5 +1,6 @@ import { Glob } from 'bun'; import { join } from 'node:path'; +import { healthResponse } from './src/server/health'; import { metricsResponse, httpRequestsTotal, @@ -79,6 +80,7 @@ const server = Bun.serve({ routes: { ...(await buildStaticRoutes()), '/metrics': (req) => metricsResponse(req), + '/health': () => healthResponse(), '/*': async (req) => { const url = new URL(req.url); const res = await withHttpMetrics(req, url.pathname, () => handler.fetch(req)); diff --git a/src/server/health.test.ts b/src/server/health.test.ts new file mode 100644 index 0000000..0d202a3 --- /dev/null +++ b/src/server/health.test.ts @@ -0,0 +1,13 @@ +import { describe, expect, it } from 'vitest'; +import { healthResponse } from './health'; + +describe('healthResponse', () => { + it('returns 200', () => { + expect(healthResponse().status).toBe(200); + }); + + it('returns ok status in body', async () => { + const body = await healthResponse().json(); + expect(body).toEqual({ status: 'ok' }); + }); +}); diff --git a/src/server/health.ts b/src/server/health.ts new file mode 100644 index 0000000..216d9e4 --- /dev/null +++ b/src/server/health.ts @@ -0,0 +1,3 @@ +export function healthResponse(): Response { + return Response.json({ status: 'ok' }); +}