25 lines
1.4 KiB
TypeScript
25 lines
1.4 KiB
TypeScript
/*
|
|
* SPEC: PJ2026-010103 HWPOD 服务。
|
|
* 实现引用: draft-2026-07-20-hwpod-temporal-split。
|
|
* 责任: 独立 HWPOD L1 Web 的固定端口、健康检查和 API proxy。
|
|
*/
|
|
import path from "node:path";
|
|
import { defineConfig, type Plugin } from "vite";
|
|
|
|
const apiUrl = process.env.HWPOD_NATIVE_API_URL;
|
|
if (!apiUrl) throw new Error("HWPOD_NATIVE_API_URL is required");
|
|
|
|
export default defineConfig({
|
|
root: path.resolve(import.meta.dirname, "../hwpod"),
|
|
server: {
|
|
host: process.env.HWPOD_WEB_HOST || "0.0.0.0",
|
|
port: requiredPort(process.env.HWPOD_WEB_PORT),
|
|
strictPort: true,
|
|
proxy: { "/v1": { target: apiUrl, changeOrigin: false }, "/health/ready": { target: apiUrl, changeOrigin: false } }
|
|
},
|
|
plugins: [healthPlugin()]
|
|
});
|
|
|
|
function healthPlugin(): Plugin { return { name: "hwpod-native-health", configureServer(server) { server.middlewares.use((request, response, next) => { if (request.url !== "/health/live") return next(); response.statusCode = 200; response.setHeader("content-type", "application/json"); response.end(JSON.stringify({ ok: true, serviceId: "hwlab-hwpod-web", status: "live", valuesPrinted: false })); }); } }; }
|
|
function requiredPort(value: string | undefined) { const port = Number.parseInt(String(value ?? ""), 10); if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("HWPOD_WEB_PORT is required and must be valid"); return port; }
|