fix: inject HWPOD native Cloud runtime config

This commit is contained in:
root
2026-07-21 09:01:06 +02:00
parent c59a814ebb
commit 6449bbd648
2 changed files with 8 additions and 2 deletions
+1 -1
View File
@@ -85,7 +85,7 @@ function serviceCommand(service: ServiceName) {
function serviceEnv(service: ServiceName, env: Record<string, string | undefined>) {
if (service === "api") return { ...process.env, ...env, HWPOD_API_HOST: requiredEnv(env, "HWPOD_API_BIND_HOST"), HWPOD_API_PORT: requiredEnv(env, "HWPOD_API_PORT") };
if (service === "worker") return { ...process.env, ...env, HWPOD_WORKER_HEALTH_HOST: requiredEnv(env, "HWPOD_WORKER_BIND_HOST"), HWPOD_WORKER_HEALTH_PORT: requiredEnv(env, "HWPOD_WORKER_HEALTH_PORT") };
return { ...process.env, ...env, HWPOD_WEB_HOST: requiredEnv(env, "HWPOD_WEB_BIND_HOST"), HWPOD_WEB_PORT: requiredEnv(env, "HWPOD_WEB_PORT"), HWPOD_NATIVE_API_URL: requiredEnv(env, "HWPOD_NATIVE_API_URL"), HWPOD_WEB_ACCESS_PROFILE_JSON: requiredEnv(env, "HWPOD_WEB_ACCESS_PROFILE_JSON") };
return { ...process.env, ...env, HWPOD_WEB_HOST: requiredEnv(env, "HWPOD_WEB_BIND_HOST"), HWPOD_WEB_PORT: requiredEnv(env, "HWPOD_WEB_PORT"), HWPOD_NATIVE_API_URL: requiredEnv(env, "HWPOD_NATIVE_API_URL"), HWPOD_WEB_RUNTIME_CONFIG: requiredEnv(env, "HWPOD_WEB_RUNTIME_CONFIG"), HWPOD_WEB_ACCESS_PROFILE_JSON: requiredEnv(env, "HWPOD_WEB_ACCESS_PROFILE_JSON") };
}
function serviceEndpoints(service: ServiceName, env: Record<string, string | undefined>) {
const prefix = service === "worker" ? "HWPOD_WORKER" : service === "api" ? "HWPOD_API" : "HWPOD_WEB";
@@ -8,6 +8,7 @@ import type { ServerResponse } from "node:http";
import vue from "@vitejs/plugin-vue";
import { defineConfig, type Plugin } from "vite";
import { parseWorkbenchNativeRuntimeConfig } from "../vite.config";
export default defineConfig(({ command }) => ({
root: fileURLToPath(new URL("..", import.meta.url)),
@@ -24,11 +25,16 @@ export default defineConfig(({ command }) => ({
}
} : undefined,
plugins: command === "serve"
? [nativeSessionPlugin(process.env.HWPOD_WEB_ACCESS_PROFILE_JSON), healthPlugin(), vue()]
? [nativeRuntimeConfigPlugin(process.env.HWPOD_WEB_RUNTIME_CONFIG), nativeSessionPlugin(process.env.HWPOD_WEB_ACCESS_PROFILE_JSON), healthPlugin(), vue()]
: [vue()]
}));
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 nativeRuntimeConfigPlugin(serialized: string | undefined): Plugin {
const config = parseWorkbenchNativeRuntimeConfig(requiredString(serialized, "HWPOD_WEB_RUNTIME_CONFIG"));
const inlineJson = JSON.stringify(config).replace(/</gu, "\\u003c");
return { name: "hwpod-native-runtime-config", transformIndexHtml() { return [{ tag: "script", injectTo: "head-prepend", children: `window.HWLAB_CLOUD_WEB_CONFIG=${inlineJson};` }]; } };
}
function nativeSessionPlugin(serialized: string | undefined): Plugin {
const profile = parseHwpodNativeAccessProfile(serialized);
const session = {