feat(backend): scaffold Fastify+TS + /health
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import Fastify, { type FastifyInstance } from "fastify";
|
||||
import type { AppConfig } from "./config.js";
|
||||
export function buildApp(_config: AppConfig): FastifyInstance {
|
||||
const app = Fastify({ logger: false });
|
||||
app.get("/health", async () => ({ status: "ok" }));
|
||||
return app;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
export interface AppConfig {
|
||||
port: number; harnessDir: string; thtBin: string; piBin: string;
|
||||
authMode: "none" | "mock" | "oidc";
|
||||
defaults: { provider?: string; model?: string; thinking?: string };
|
||||
maxPiProcesses: number;
|
||||
}
|
||||
export function loadConfig(env: Record<string, string | undefined>): AppConfig {
|
||||
return {
|
||||
port: Number(env.PORT ?? 8787),
|
||||
harnessDir: env.THT_HARNESS_DIR ?? "../harness",
|
||||
thtBin: env.THT_BIN ?? "tht",
|
||||
piBin: env.PI_BIN ?? "pi",
|
||||
authMode: (env.AUTH_MODE as AppConfig["authMode"]) ?? "none",
|
||||
defaults: { provider: env.PI_PROVIDER, model: env.PI_MODEL, thinking: env.PI_THINKING },
|
||||
maxPiProcesses: Number(env.MAX_PI_PROCESSES ?? 4),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { buildApp } from "./app.js";
|
||||
import { loadConfig } from "./config.js";
|
||||
const config = loadConfig(process.env);
|
||||
const app = buildApp(config);
|
||||
app.listen({ port: config.port, host: "127.0.0.1" })
|
||||
.then((addr) => console.log(`backend listening on ${addr}`));
|
||||
Reference in New Issue
Block a user