// Disposable drill fixture. Marker files simulate observations, not a real DB or deadlock. import { createServer } from 'node:http'; import { existsSync } from 'node:fs'; import { pathToFileURL } from 'node:url'; import { statusFor } from './health.ts'; export { statusFor } from './health.ts'; /** @param {() => import('./health.ts').HealthState} readState */ export function createFixtureServer(readState) { return createServer((request, response) => { const status = statusFor(request.url, readState()); response.writeHead(status, { 'Content-Type': 'text/plain', 'Cache-Control': 'no-store', 'X-Replica': process.env.HOSTNAME ?? 'local' }); response.end(status === 200 ? 'ok\n' : 'unavailable\n'); }); } if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { const startedAt = Date.now(); createFixtureServer(() => ({ initialized: Date.now() - startedAt >= Number(process.env.STARTUP_MS ?? 50000), stuck: existsSync('/tmp/stuck'), databaseDown: existsSync('/tmp/database-down') })).listen(Number(process.env.PORT ?? 8080), '0.0.0.0'); }