api/src/routes/public/stats.ts
36 lines · 824 bytes
3 symbols in this file
1// Aggregate counts plus health route
2import { createRoute } from '@hono/zod-openapi'
3import { stats } from '@/lib/data'
4import { newApp } from '@/lib/openapi'
5import { Envelope, HealthSchema, Ok, StatsSchema } from '@/schemas'
6
7const app = newApp()
8
9const statsRoute = createRoute({
10 method: 'get',
11 path: '/stats',
12 tags: ['Public'],
13 summary: 'Stats',
14 responses: { 200: Ok(Envelope(StatsSchema)) },
15})
16
17app.openapi(statsRoute, (c) => c.json({ data: stats() }))
18
19const healthRoute = createRoute({
20 method: 'get',
21 path: '/health',
22 tags: ['Public'],
23 summary: 'Health',
24 responses: { 200: Ok(Envelope(HealthSchema)) },
25})
26
27app.openapi(healthRoute, (c) =>
28 c.json({
29 data: {
30 status: 'ok' as const,
31 uptime: typeof process !== 'undefined' ? process.uptime() : 0,
32 },
33 }),
34)
35
36export default app