Files
pikasTech-HWLAB/cmd/hwlab-hwpod-api/main.ts
T

13 lines
1.2 KiB
TypeScript

#!/usr/bin/env bun
import { createHwpodHttpApp } from "../../internal/hwpod/http.ts";
import { hwpodRuntime } from "../../internal/hwpod/runtime.ts";
const runtime = hwpodRuntime();
const app = createHwpodHttpApp({ runtimeApiUrl: runtime.runtimeApiUrl, runtimeApiAuthorization: runtime.runtimeApiAuthorization, temporal: runtime.temporal });
const host = process.env.HWPOD_API_HOST || "0.0.0.0";
const port = positivePort(process.env.HWPOD_API_PORT, 6681);
const server = Bun.serve({ hostname: host, port, fetch: request => app.fetch(request) });
process.stdout.write(`${JSON.stringify({ serviceId: "hwlab-hwpod-api", status: "listening", host, port: server.port, temporalNamespace: runtime.namespace, taskQueue: runtime.taskQueue, valuesPrinted: false })}\n`);
for (const signal of ["SIGINT", "SIGTERM"] as const) process.once(signal, async () => { server.stop(true); await app.close(); process.exit(0); });
function positivePort(value: string | undefined, fallback: number) { const parsed = Number.parseInt(String(value ?? fallback), 10); if (!Number.isInteger(parsed) || parsed < 1 || parsed > 65535) throw new Error("HWPOD_API_PORT must be a valid port"); return parsed; }