From e0c36b71e60dedc8f89cd85ee340e54f8c9057a2 Mon Sep 17 00:00:00 2001 From: weishu Date: Tue, 13 Jan 2026 20:32:47 +0800 Subject: [PATCH] Remove env-based tunnel toggle --- cli/src/commands/server.ts | 14 +++--------- server/src/config/serverSettings.ts | 14 ------------ server/src/config/settings.ts | 1 - server/src/configuration.ts | 6 ------ server/src/index.ts | 33 +++++++++++++++++++++++------ 5 files changed, 29 insertions(+), 39 deletions(-) diff --git a/cli/src/commands/server.ts b/cli/src/commands/server.ts index 86f8b118..df51357c 100644 --- a/cli/src/commands/server.ts +++ b/cli/src/commands/server.ts @@ -1,8 +1,8 @@ import chalk from 'chalk' import type { CommandDefinition, CommandContext } from './types' -function parseServerArgs(args: string[]): { host?: string; port?: string; relay?: boolean } { - const result: { host?: string; port?: string; relay?: boolean } = {} +function parseServerArgs(args: string[]): { host?: string; port?: string } { + const result: { host?: string; port?: string } = {} for (let i = 0; i < args.length; i++) { const arg = args[i] @@ -14,10 +14,6 @@ function parseServerArgs(args: string[]): { host?: string; port?: string; relay? result.host = arg.slice('--host='.length) } else if (arg.startsWith('--port=')) { result.port = arg.slice('--port='.length) - } else if (arg === '--relay') { - result.relay = true - } else if (arg === '--no-relay') { - result.relay = false } } @@ -29,7 +25,7 @@ export const serverCommand: CommandDefinition = { requiresRuntimeAssets: false, run: async (context: CommandContext) => { try { - const { host, port, relay } = parseServerArgs(context.commandArgs) + const { host, port } = parseServerArgs(context.commandArgs) if (host) { process.env.WEBAPP_HOST = host @@ -37,10 +33,6 @@ export const serverCommand: CommandDefinition = { if (port) { process.env.WEBAPP_PORT = port } - if (relay !== undefined) { - process.env.HAPI_RELAY = relay ? 'true' : 'false' - } - await import('../../../server/src/index') } catch (error) { console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error') diff --git a/server/src/config/serverSettings.ts b/server/src/config/serverSettings.ts index d04f41be..9c316b03 100644 --- a/server/src/config/serverSettings.ts +++ b/server/src/config/serverSettings.ts @@ -17,7 +17,6 @@ export interface ServerSettings { webappPort: number webappUrl: string corsOrigins: string[] - tunnelEnabled: boolean } export interface ServerSettingsResult { @@ -29,7 +28,6 @@ export interface ServerSettingsResult { webappPort: 'env' | 'file' | 'default' webappUrl: 'env' | 'file' | 'default' corsOrigins: 'env' | 'file' | 'default' - tunnelEnabled: 'env' | 'file' | 'default' } savedToFile: boolean } @@ -93,7 +91,6 @@ export async function loadServerSettings(dataDir: string): Promise file > null let telegramBotToken: string | null = null @@ -185,16 +182,6 @@ export async function loadServerSettings(dataDir: string): Promise file > false (default disabled) - let tunnelEnabled = false - if (process.env.HAPI_RELAY !== undefined) { - tunnelEnabled = process.env.HAPI_RELAY === 'true' || process.env.HAPI_RELAY === '1' - sources.tunnelEnabled = 'env' - } else if (settings.tunnelEnabled !== undefined) { - tunnelEnabled = settings.tunnelEnabled - sources.tunnelEnabled = 'file' - } - // Save settings if any new values were added if (needsSave) { await writeSettings(settingsFile, settings) @@ -208,7 +195,6 @@ export async function loadServerSettings(dataDir: string): Promise | null = null @@ -54,7 +73,8 @@ async function main() { // Load configuration (async - loads from env/file with persistence) const config = await createConfiguration() - const relayApiDomain = process.env.HAPI_RELAY_API || null + const relayApiDomain = process.env.HAPI_RELAY_API || 'relay.hapi.run' + const relayFlag = resolveRelayFlag(process.argv) // Display CLI API token information if (config.cliApiTokenIsNew) { @@ -88,11 +108,10 @@ async function main() { } // Display tunnel status - if (config.tunnelEnabled) { - const apiDomain = relayApiDomain || 'relay.hapi.run' - console.log(`[Server] Tunnel: enabled (${formatSource(config.sources.tunnelEnabled)}), API: ${apiDomain}`) + if (relayFlag.enabled) { + console.log(`[Server] Tunnel: enabled (${relayFlag.source}), API: ${relayApiDomain}`) } else { - console.log(`[Server] Tunnel: disabled (${formatSource(config.sources.tunnelEnabled)})`) + console.log(`[Server] Tunnel: disabled (${relayFlag.source})`) } const store = new Store(config.dbPath) @@ -158,7 +177,7 @@ async function main() { // Initialize tunnel AFTER web server is ready let tunnelUrl: string | null = null - if (config.tunnelEnabled) { + if (relayFlag.enabled) { tunnelManager = new TunnelManager({ localPort: config.webappPort, enabled: true, @@ -171,7 +190,7 @@ async function main() { tunnelUrl = await tunnelManager.start() } catch (error) { console.error('[Tunnel] Failed to start:', error instanceof Error ? error.message : error) - console.log('[Tunnel] Server continuing without tunnel. Use --no-relay to disable.') + console.log('[Tunnel] Server continuing without tunnel. Restart without --relay to disable.') } }