Skip to content

Bug: the program doesn't respect the host setting in the config.toml #76

Description

@taskkillstar

Problem Description

Currently, EasyCLIProxyAPI hardcodes "127.0.0.1" in "management_endpoint" (src-tauri/src/main.rs, Lines 10005-10014):

fn management_endpoint(config: &GuiConfigFile, path: &str) -> Result<String, String> {
    if config.port == 0 {
        return Err("内核端口无效".to_string());
    }
    let path = path.trim_start_matches('/');
    Ok(format!(
        "http://127.0.0.1:{}/v0/management/{path}",
        config.port
    ))
}

Because of this hardcoded loopback address:

Users who deploy CLIProxyAPI on a remote server or remote VM cannot connect EasyCLIProxyAPI directly by setting host = "your-remote-host-or-ip" in gui-config.toml / config.toml.
All management API calls (/v0/management/...) are strictly sent to 127.0.0.1, ignoring any custom host setting configured by the user.

Proposed Changes
Update management_endpoint in src-tauri/src/main.rs to derive the management target host from config.host:

If config.host is a custom IP address (e.g. 192.168.1.100) or hostname (e.g. proxy.example.com), management_endpoint uses that host.
If config.host is empty or set to 0.0.0.0 (wildcard bind address), it safely falls back to 127.0.0.1 to avoid invalid HTTP connection targets.

 fn management_endpoint(config: &GuiConfigFile, path: &str) -> Result<String, String> {
     if config.port == 0 {
         return Err("内核端口无效".to_string());
     }
+    let host = config.host.trim();
+    let target_host = if host.is_empty() || host == "0.0.0.0" {
+        "127.0.0.1"
+    } else {
+        host
+    };
     let path = path.trim_start_matches('/');
     Ok(format!(
-        "http://127.0.0.1:{}/v0/management/{path}",
+        "http://{target_host}:{}/v0/management/{path}",
         config.port
     ))
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions