Skip to content

Commit c1f7e4d

Browse files
committed
fix(health): accept query params in health checks
1 parent 24bf739 commit c1f7e4d

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

apps/sim/app/api/health/route.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* @vitest-environment node
33
*/
4+
import appPackage from '@/package.json'
45
import { NextRequest } from 'next/server'
56
import { afterEach, describe, expect, it } from 'vitest'
67
import { GET } from '@/app/api/health/route'
@@ -29,6 +30,12 @@ describe('GET /api/health', () => {
2930
})
3031
})
3132

33+
it('accepts query parameters from health-checking clients', async () => {
34+
const response = await GET(new NextRequest('http://localhost/api/health?_=123'))
35+
36+
expect(response.status).toBe(200)
37+
})
38+
3239
it('falls back to the package version when runtime metadata is not provided', async () => {
3340
process.env.APP_VERSION = ''
3441
process.env.NEXT_PUBLIC_APP_VERSION = ''
@@ -42,7 +49,7 @@ describe('GET /api/health', () => {
4249
await expect(response.json()).resolves.toEqual({
4350
status: 'ok',
4451
timestamp: expect.any(String),
45-
version: '0.1.0',
52+
version: appPackage.version,
4653
commit: null,
4754
})
4855
})

apps/sim/app/api/health/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ function getAppCommit(): string | null {
2020
export async function GET(request: NextRequest): Promise<Response> {
2121
const parsed = await parseRequest(healthContract, request, {})
2222
if (!parsed.success) return parsed.response
23-
2423
return NextResponse.json(
2524
{
2625
status: 'ok',

apps/sim/lib/api/contracts/health.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { z } from 'zod'
2-
import { noInputSchema } from '@/lib/api/contracts/primitives'
32
import { defineRouteContract } from '@/lib/api/contracts/types'
43

4+
const healthQuerySchema = z.object({}).passthrough()
55
export const healthResponseSchema = z.object({
66
status: z.literal('ok'),
77
timestamp: z.string(),
@@ -14,7 +14,7 @@ export type HealthResponse = z.output<typeof healthResponseSchema>
1414
export const healthContract = defineRouteContract({
1515
method: 'GET',
1616
path: '/api/health',
17-
query: noInputSchema,
17+
query: healthQuerySchema,
1818
response: {
1919
mode: 'json',
2020
schema: healthResponseSchema,

0 commit comments

Comments
 (0)