Files
hapi/cli/src/ui/apiUrlInit.ts
T
weishu 9e335fa305 refactor: rename configuration variables for clarity
Standardize naming across CLI and server components:
- CLI: serverUrl → apiUrl, HAPI_SERVER_URL → HAPI_API_URL
- Server: webapp* → listen*, miniAppUrl → publicUrl, WEBAPP_* → HAPI_LISTEN_*, WEBAPP_URL → HAPI_PUBLIC_URL
- Rename serverUrlInit.ts → apiUrlInit.ts with updated logic for backward compatibility
- Update all imports, function calls, and documentation accordingly
2026-01-19 12:57:37 +08:00

37 lines
1.0 KiB
TypeScript

/**
* API URL initialization module
*
* Handles HAPI_API_URL initialization with priority:
* 1. Environment variable (highest - allows temporary override)
* 2. Settings file (~/.hapi/settings.json)
* 3. Default value (http://localhost:3006)
*/
import { configuration } from '@/configuration'
import { readSettings } from '@/persistence'
/**
* Initialize API URL
* Must be called before any API operations
*/
export async function initializeApiUrl(): Promise<void> {
// 1. Environment variable has highest priority (allows temporary override)
if (process.env.HAPI_API_URL) {
return
}
// 2. Read from settings file (new name first, then legacy)
const settings = await readSettings()
if (settings.apiUrl) {
configuration._setApiUrl(settings.apiUrl)
return
}
if (settings.serverUrl) {
// Migrate from legacy field name
configuration._setApiUrl(settings.serverUrl)
return
}
// 3. Default value already set in configuration constructor
}