fix: update desktop server configuration for consistent port handling and access

This commit is contained in:
ciat-777
2026-03-15 22:02:03 +08:00
parent 4b42751953
commit 6ca08c1052
8 changed files with 45 additions and 33 deletions
+10 -1
View File
@@ -23,6 +23,7 @@ type DesktopServerWorkingDirInput = {
isPackaged: boolean;
};
const DEFAULT_DESKTOP_SERVER_PORT = 4000;
const DEFAULT_READY_TIMEOUT_MS = 30_000;
const DEFAULT_READY_INTERVAL_MS = 250;
@@ -31,9 +32,11 @@ function delay(ms: number) {
}
export function buildDesktopServerEnv(input: DesktopServerEnvInput): NodeJS.ProcessEnv {
const host = (input.inheritedEnv?.HOST || '0.0.0.0').trim() || '0.0.0.0';
return {
...(input.inheritedEnv || {}),
HOST: '127.0.0.1',
HOST: host,
PORT: String(input.port),
DATA_DIR: input.userDataDir,
METAPI_DESKTOP: '1',
@@ -49,6 +52,12 @@ export function createDesktopHealthUrl(port: number): string {
return `${createDesktopServerUrl(port)}/api/desktop/health`;
}
export function resolveDesktopServerPort(env?: NodeJS.ProcessEnv): number {
const forcedPort = Number.parseInt(env?.METAPI_DESKTOP_SERVER_PORT || '', 10);
if (Number.isFinite(forcedPort) && forcedPort > 0) return forcedPort;
return DEFAULT_DESKTOP_SERVER_PORT;
}
export function resolveDesktopServerWorkingDir(input: DesktopServerWorkingDirInput): string {
return input.isPackaged ? input.resourcesPath : input.appPath;
}