feat: add serverUrl configuration support with settings.json fallback

Implement serverUrl initialization following the cliApiToken design pattern:
- Environment variable HAPI_SERVER_URL (highest priority, allows temporary override)
- settings.json serverUrl field (user persistent configuration)
- Default value 'http://localhost:3006' (fallback)

Changes:
- Add serverUrl field to Settings interface (persistence.ts)
- Convert serverUrl to private property with getter/setter (configuration.ts)
- Create initializeServerUrl module to load from settings (serverUrlInit.ts)
- Integrate serverUrl initialization in tokenInit flow (tokenInit.ts)
- Skip auto-start when serverUrl is configured in settings (autoStartServer.ts)
This commit is contained in:
weishu
2026-01-08 10:37:37 +08:00
parent cb69001385
commit 9dc69d1e80
5 changed files with 56 additions and 3 deletions
+9 -1
View File
@@ -96,8 +96,16 @@ async function shouldAutoStartServer(): Promise<boolean> {
return false
}
// Condition 2: cliApiToken exists in settings.json (server was previously started)
// Condition 2: Check settings.json
const settings = await readSettings()
// 2a: serverUrl is set in settings.json (user configured a specific server)
if (settings.serverUrl) {
logger.debug('[AUTO-START] serverUrl is set in settings.json, skipping auto-start')
return false
}
// 2b: cliApiToken exists in settings.json (server was previously started)
if (!settings.cliApiToken) {
logger.debug('[AUTO-START] No cliApiToken in settings, skipping auto-start')
return false