chore: scaffold turbo monorepo with hono api and react admin web
This commit is contained in:
11
apps/api/src/modules/health/get-status/route.ts
Normal file
11
apps/api/src/modules/health/get-status/route.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Hono } from 'hono'
|
||||
|
||||
import { resultJson } from '@/lib/result-json'
|
||||
import type { AppEnv } from '@/types'
|
||||
|
||||
import { GetStatus } from './use-case'
|
||||
|
||||
/** GET /health — liveness probe. */
|
||||
export const getStatusRoute = new Hono<AppEnv>()
|
||||
|
||||
getStatusRoute.get('/', (c) => resultJson(c, new GetStatus().execute()))
|
||||
18
apps/api/src/modules/health/get-status/use-case.test.ts
Normal file
18
apps/api/src/modules/health/get-status/use-case.test.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { describe, expect, it } from 'bun:test'
|
||||
|
||||
import { GetStatus } from './use-case'
|
||||
|
||||
describe('GetStatus', () => {
|
||||
it('reports ok with the current uptime and timestamp', () => {
|
||||
const now = new Date('2026-01-01T00:00:00.000Z')
|
||||
const result = new GetStatus(() => now).execute()
|
||||
|
||||
expect(result.ok).toBe(true)
|
||||
if (!result.ok) throw new Error('expected the use case to succeed')
|
||||
expect(result.value).toEqual({
|
||||
status: 'ok',
|
||||
uptimeSeconds: expect.any(Number),
|
||||
timestamp: '2026-01-01T00:00:00.000Z',
|
||||
})
|
||||
})
|
||||
})
|
||||
23
apps/api/src/modules/health/get-status/use-case.ts
Normal file
23
apps/api/src/modules/health/get-status/use-case.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Ok, type Result, type ProblemDetails } from '@superlist/shared'
|
||||
|
||||
export type HealthStatus = {
|
||||
status: 'ok'
|
||||
uptimeSeconds: number
|
||||
timestamp: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the liveness status of the process.
|
||||
* No dependencies and no failure mode: it must always succeed.
|
||||
*/
|
||||
export class GetStatus {
|
||||
constructor(private readonly now: () => Date = () => new Date()) {}
|
||||
|
||||
execute(): Result<HealthStatus, ProblemDetails> {
|
||||
return Ok({
|
||||
status: 'ok',
|
||||
uptimeSeconds: Math.round(process.uptime()),
|
||||
timestamp: this.now().toISOString(),
|
||||
})
|
||||
}
|
||||
}
|
||||
8
apps/api/src/modules/health/index.ts
Normal file
8
apps/api/src/modules/health/index.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Hono } from 'hono'
|
||||
|
||||
import type { AppEnv } from '@/types'
|
||||
|
||||
import { getStatusRoute } from './get-status/route'
|
||||
|
||||
/** `health` module: every feature of the module is mounted here. */
|
||||
export const healthModule = new Hono<AppEnv>().route('/', getStatusRoute)
|
||||
Reference in New Issue
Block a user