fix: 恢复 Cloud Web SPA 运行配置

This commit is contained in:
root
2026-07-11 12:06:57 +02:00
parent 9c91ea0c5c
commit 7939c4ca92
9 changed files with 74 additions and 3 deletions
+10 -1
View File
@@ -36,6 +36,7 @@ const opencodeTickets = new Map();
export async function serveCloudWeb(options) {
installCloudWebProcessErrorHandlers({ serviceId: options.serviceId });
await validateCloudWebRuntimeConfig();
const server = createCloudWebServer(options);
server.listen(options.port, "0.0.0.0", () => {
process.stdout.write(JSON.stringify({
@@ -119,7 +120,7 @@ export function createCloudWebServer({
logCloudWebRuntimeEvent("cloud-web-client-disconnect", { serviceId, request, error });
return;
}
// Try the next root for ordinary filesystem misses.
if (!isStaticFileMiss(error)) throw error;
}
}
@@ -142,6 +143,14 @@ export function createCloudWebServer({
});
}
export async function validateCloudWebRuntimeConfig() {
await runtimeConfigFromEnv();
}
function isStaticFileMiss(error) {
return error?.code === "ENOENT" || error?.code === "ENOTDIR";
}
async function staticResponseBody({ candidate, relativePath, type, request, url, cloudApiBaseUrl, cloudApiProxyTimeoutMs }) {
const body = await readFile(candidate);
if (relativePath !== "index.html" || !String(type).startsWith("text/html")) return body;
@@ -7,7 +7,7 @@ import path from "node:path";
import test from "node:test";
import { gzipSync } from "node:zlib";
import { createCloudWebServer, isClientDisconnectError } from "./cloud-web-runtime.mjs";
import { createCloudWebServer, isClientDisconnectError, validateCloudWebRuntimeConfig } from "./cloud-web-runtime.mjs";
test("cloud web classifies Bun client disconnect ECONNRESET as non-fatal", () => {
const error = new Error("aborted");
@@ -16,6 +16,26 @@ test("cloud web classifies Bun client disconnect ECONNRESET as non-fatal", () =>
assert.equal(isClientDisconnectError(new Error("database migration failed")), false);
});
test("cloud web rejects a missing refresh replay capability before listening", async () => {
const restoreEnv = withEnv({
HWLAB_CLOUD_WEB_DISPLAY_TIME_ZONE: "Asia/Shanghai",
HWLAB_CLOUD_WEB_DISPLAY_TIME_LOCALE: "zh-CN",
HWLAB_CLOUD_WEB_DISPLAY_TIME_LABEL: "北京时间",
HWLAB_WORKBENCH_LIVE_KAFKA_SSE_ENABLED: "true",
HWLAB_WORKBENCH_KAFKA_REFRESH_REPLAY_ENABLED: undefined,
HWLAB_WORKBENCH_PROJECTION_REALTIME_ENABLED: "false",
HWLAB_WORKBENCH_KAFKA_DEBUG_REPLAY_ENABLED: "true",
HWLAB_WORKBENCH_RAW_HWLAB_EVENT_WINDOW_ENABLED: "true",
HWLAB_WORKBENCH_RAW_HWLAB_EVENT_WINDOW_MAX_ENTRIES: "200",
HWLAB_WORKBENCH_RAW_HWLAB_EVENT_WINDOW_MAX_RETAINED_BYTES: "1048576"
});
try {
await assert.rejects(validateCloudWebRuntimeConfig(), /HWLAB_WORKBENCH_KAFKA_REFRESH_REPLAY_ENABLED/u);
} finally {
restoreEnv();
}
});
test("cloud web auth requests are proxied once", async () => {
let upstreamRequests = 0;
const upstream = createServer((request, response) => {