18 lines
1.4 KiB
TypeScript
18 lines
1.4 KiB
TypeScript
#!/usr/bin/env bun
|
|
/*
|
|
* SPEC: PJ2026-010103 HWPOD 服务;
|
|
* PJ2026-01010305 71FREQ 预装 draft-2026-06-26-71freq-v03-hwpod-preinstall。
|
|
* 责任: 启动拥有 runtime spec registry 与 Temporal 提交能力的 HWPOD API。
|
|
*/
|
|
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, specRegistry: runtime.specRegistry });
|
|
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; }
|