From 0163eb372d448aeaa8444fb174b95c5162e544ee Mon Sep 17 00:00:00 2001 From: weishu Date: Wed, 14 Jan 2026 12:26:00 +0800 Subject: [PATCH] fix: set default TUNWG_PATH and support ~ in HAPI_HOME Extract getHapiHome() helper to properly expand ~ prefix in HAPI_HOME env var. Set TUNWG_PATH default to $HAPI_HOME/tunwg when not specified. --- server/src/tunnel/tunnelManager.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/src/tunnel/tunnelManager.ts b/server/src/tunnel/tunnelManager.ts index 1b25c6b0..cdffd345 100644 --- a/server/src/tunnel/tunnelManager.ts +++ b/server/src/tunnel/tunnelManager.ts @@ -17,6 +17,12 @@ function isBunCompiled(): boolean { return typeof process.execPath === 'string' && !process.execPath.includes('bun') } +function getHapiHome(): string { + return process.env.HAPI_HOME + ? process.env.HAPI_HOME.replace(/^~/, homedir()) + : join(homedir(), '.hapi') +} + function getPlatformDir(): string { const platformName = platform() const archName = arch() @@ -39,7 +45,7 @@ function getTunwgPath(): string { const tunwgBinary = isWin ? 'tunwg.exe' : 'tunwg' if (isBunCompiled()) { - const hapiHome = process.env.HAPI_HOME || join(homedir(), '.hapi') + const hapiHome = getHapiHome() const packageJson = require('../../../cli/package.json') const runtimePath = join(hapiHome, 'runtime', packageJson.version) return join(runtimePath, 'tools', 'tunwg', tunwgBinary) @@ -106,6 +112,10 @@ export class TunnelManager { const env: Record = { ...process.env as Record } + if (!env.TUNWG_PATH) { + env.TUNWG_PATH = join(getHapiHome(), 'tunwg') + } + if (this.config.apiDomain) { env.TUNWG_API = this.config.apiDomain }