diff --git a/src/cliproxy/remote-proxy-client.ts b/src/cliproxy/remote-proxy-client.ts index 5b0b771c..b8ab2c4e 100644 --- a/src/cliproxy/remote-proxy-client.ts +++ b/src/cliproxy/remote-proxy-client.ts @@ -52,16 +52,30 @@ export interface RemoteProxyClientConfig { /** Default timeout for remote proxy requests (aggressive for CLI UX) */ const DEFAULT_TIMEOUT_MS = 2000; +/** Default CLIProxyAPI port */ +const DEFAULT_CLIPROXY_PORT = 8317; + /** - * Get default port for protocol - * HTTP defaults to 8317 (CLIProxyAPI default), HTTPS to 443 (standard SSL) + * Get standard web port for protocol (for URL display omission) + * These are the ports that browsers/HTTP clients use by default. + * HTTP: 80, HTTPS: 443 */ -function getDefaultPort(protocol: 'http' | 'https'): number { - return protocol === 'https' ? 443 : 8317; +function getStandardWebPort(protocol: 'http' | 'https'): number { + return protocol === 'https' ? 443 : 80; } /** - * Build URL for remote proxy, intelligently omitting default ports + * Get effective port for CLIProxyAPI connection + * If port is provided, use it. Otherwise use CLIProxyAPI default (8317). + */ +function getEffectivePort(port: number | undefined): number { + return port ?? DEFAULT_CLIPROXY_PORT; +} + +/** + * Build URL for remote proxy + * Only omits port from URL if it matches standard web ports (80/443), + * otherwise always includes the port for clarity. */ function buildProxyUrl( host: string, @@ -69,11 +83,12 @@ function buildProxyUrl( protocol: 'http' | 'https', path: string ): string { - const defaultPort = getDefaultPort(protocol); - const effectivePort = port ?? defaultPort; + const effectivePort = getEffectivePort(port); + const standardWebPort = getStandardWebPort(protocol); - // Omit port from URL if it matches the default for the protocol - if (effectivePort === defaultPort) { + // Only omit port from URL if it matches the standard web port for the protocol + // e.g., HTTP on port 80 or HTTPS on port 443 + if (effectivePort === standardWebPort) { return `${protocol}://${host}${path}`; } return `${protocol}://${host}:${effectivePort}${path}`; diff --git a/src/config/unified-config-loader.ts b/src/config/unified-config-loader.ts index ec2c4fab..249ecd38 100644 --- a/src/config/unified-config-loader.ts +++ b/src/config/unified-config-loader.ts @@ -309,6 +309,27 @@ function generateYamlWithComments(config: UnifiedConfig): string { ); lines.push(''); + // CLIProxy Server section (remote proxy configuration) - placed right after cliproxy + if (config.cliproxy_server) { + lines.push('# ----------------------------------------------------------------------------'); + lines.push('# CLIProxy Server: Remote proxy connection settings'); + lines.push('# Configure via Dashboard (`ccs config`) > Proxy tab.'); + lines.push('#'); + lines.push('# remote: Connect to a remote CLIProxyAPI instance'); + lines.push('# fallback: Use local proxy if remote is unreachable'); + lines.push('# local: Local proxy settings (port, auto-start)'); + lines.push('# ----------------------------------------------------------------------------'); + lines.push( + yaml + .dump( + { cliproxy_server: config.cliproxy_server }, + { indent: 2, lineWidth: -1, quotingType: '"' } + ) + .trim() + ); + lines.push(''); + } + // Preferences section lines.push('# ----------------------------------------------------------------------------'); lines.push('# Preferences: User settings'); @@ -374,27 +395,6 @@ function generateYamlWithComments(config: UnifiedConfig): string { lines.push(''); } - // CLIProxy Server section (remote proxy configuration) - if (config.cliproxy_server) { - lines.push('# ----------------------------------------------------------------------------'); - lines.push('# CLIProxy Server: Remote proxy connection settings'); - lines.push('# Configure via Dashboard (`ccs config`) > Proxy tab.'); - lines.push('#'); - lines.push('# remote: Connect to a remote CLIProxyAPI instance'); - lines.push('# fallback: Use local proxy if remote is unreachable'); - lines.push('# local: Local proxy settings (port, auto-start)'); - lines.push('# ----------------------------------------------------------------------------'); - lines.push( - yaml - .dump( - { cliproxy_server: config.cliproxy_server }, - { indent: 2, lineWidth: -1, quotingType: '"' } - ) - .trim() - ); - lines.push(''); - } - // Global env section if (config.global_env) { lines.push('# ----------------------------------------------------------------------------');