fix: inject HWPOD native Cloud runtime config
This commit is contained in:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user