SPB Git forge

spb/cancerindex

Public
37commits 1branches 0releases
2.9 MBsize
maindefault branch
10 days agolast push
TypeScript 97.2% SQL 1.5% CSS 0.6% JavaScript 0.5%
2.2 KB · 34 lines typescript
Raw Blame History
1import type { FastifyPluginAsyncZod } from 'fastify-type-provider-zod';2import { z } from 'zod';3import { dataRelease } from '../lib/envelope.js';45export const healthRoutes: FastifyPluginAsyncZod = async (app) => {6  // Root of the API host: a minimal, honest landing (used while the web app is not yet in front).7  app.get('/', { schema: { hide: true }, config: { rateLimit: false } }, async (_req, reply) => {8    reply.type('text/html; charset=utf-8');9    return `<!doctype html><html lang="en"><head><meta charset="utf-8"><title>CancerIndex API</title>10<meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex">11<style>body{font:16px/1.5 -apple-system,Inter,Segoe UI,sans-serif;max-width:720px;margin:8vh auto;padding:0 24px;color:#1f2321;background:#fafaf7}h1{font-family:Georgia,serif;font-weight:500;letter-spacing:-.01em}code,a{color:#155e63}ul{padding-left:1.2em}small{color:#666}</style></head>12<body><h1>CancerIndex <small>— the global index of cancer</small></h1>13<p>This host serves the public API (v1). The web interface is being deployed.</p>14<ul><li><a href="/v1/docs">API documentation (OpenAPI)</a></li><li><a href="/v1/stats">/v1/stats</a> — live database counts</li><li><a href="/v1/cancers?level=top">/v1/cancers?level=top</a> — top-level cancer set</li><li><a href="/v1/search?q=glioblastoma">/v1/search?q=glioblastoma</a></li><li><a href="/v1/sources">/v1/sources</a> — source registry and license status</li><li><a href="/healthz">/healthz</a></li></ul>15<p><small>CancerIndex is a research and information platform. It is not a physician, does not diagnose, and does not recommend treatment.</small></p></body></html>`;16  });17  app.get(18    '/healthz',19    {20      schema: {21        tags: ['system'],22        summary: 'Liveness/readiness probe',23        response: { 200: z.object({ ok: z.boolean(), dataRelease: z.string(), db: z.boolean(), service: z.string(), uptimeSeconds: z.number() }) },24      },25      config: { rateLimit: false },26    },27    async (_req, reply) => {28      const db = await app.dbHealthy();29      reply.code(db ? 200 : 200);30      return { ok: db, dataRelease: dataRelease(), db, service: 'cancerindex-api', uptimeSeconds: Math.round(process.uptime()) };31    },32  );33};34