Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 2 additions & 0 deletions server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Glob } from 'bun';
import { join } from 'node:path';
import { healthResponse } from './src/server/health';
import {
metricsResponse,
httpRequestsTotal,
Expand Down Expand Up @@ -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));
Expand Down
13 changes: 13 additions & 0 deletions src/server/health.test.ts
Original file line number Diff line number Diff line change
@@ -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' });
});
});
3 changes: 3 additions & 0 deletions src/server/health.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function healthResponse(): Response {
return Response.json({ status: 'ok' });
}