merge: 修复 HWPOD 节点接入路由

This commit is contained in:
root
2026-07-21 13:49:12 +02:00
8 changed files with 181 additions and 131 deletions
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { parseHwpodNativeAccessProfile } from "./hwpod-native-vite.config";
import { hwpodNativeProxy, parseHwpodNativeAccessProfile } from "./hwpod-native-vite.config";
import { firstAllowedNavPath } from "../src/stores/auth";
describe("HWPOD native Cloud Console profile", () => {
@@ -17,4 +17,10 @@ describe("HWPOD native Cloud Console profile", () => {
it("fails closed without a declared navigation profile", () => {
expect(() => parseHwpodNativeAccessProfile(undefined)).toThrow(/HWPOD_WEB_ACCESS_PROFILE_JSON/u);
});
it("proxies onboarding metadata and downloads to the independent HWPOD API", () => {
expect(hwpodNativeProxy("http://127.0.0.1:6681")).toMatchObject({
"/v1/hwlab-node": { target: "http://127.0.0.1:6681", changeOrigin: false },
});
});
});
@@ -19,17 +19,22 @@ export default defineConfig(({ command }) => ({
host: requiredString(process.env.HWPOD_WEB_HOST, "HWPOD_WEB_HOST"),
port: requiredPort(process.env.HWPOD_WEB_PORT),
strictPort: true,
proxy: {
"/v1/hwpod-node/ws": { target: requiredApiUrl(), changeOrigin: false, ws: true },
"/v1/hwpod": { target: requiredApiUrl(), changeOrigin: false },
"/health/ready": { target: requiredApiUrl(), changeOrigin: false },
}
proxy: hwpodNativeProxy(requiredApiUrl())
} : undefined,
plugins: command === "serve"
? [nativeRuntimeConfigPlugin(process.env.HWPOD_WEB_RUNTIME_CONFIG), nativeSessionPlugin(process.env.HWPOD_WEB_ACCESS_PROFILE_JSON), healthPlugin(), vue()]
: [vue()]
}));
export function hwpodNativeProxy(target: string) {
return {
"/v1/hwpod-node/ws": { target, changeOrigin: false, ws: true },
"/v1/hwpod": { target, changeOrigin: false },
"/v1/hwlab-node": { target, changeOrigin: false },
"/health/ready": { target, changeOrigin: false },
};
}
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"));