From bf5e6b7079ceeec39edd3efc69470c34a1781e6a Mon Sep 17 00:00:00 2001 From: Sergei Patrikeev Date: Mon, 20 Oct 2025 21:21:04 +0100 Subject: [PATCH] feat: add environment variables for public-facing URLs Allow overriding public URLs via environment variables when running behind a reverse proxy. This fixes an issue where the UI would try to connect to bind addresses (e.g., http://0.0.0.0:8899) instead of the public-facing URLs. The UI runs in the browser (client-side) and needs to know the public URLs to connect back to the API, not the internal bind addresses used by the Docker container. New environment variables: - SURFPOOL_PUBLIC_RPC_URL: Public RPC endpoint URL - SURFPOOL_PUBLIC_WS_URL: Public WebSocket endpoint URL - SURFPOOL_PUBLIC_STUDIO_URL: Public Studio UI URL Also fix Dockerfile to expose correct port 18488 instead of outdated 8488. (cherry picked from commit b14aa71ffe2915f5b3c58dab21c8ddb312b409dd) --- Dockerfile | 2 +- crates/cli/src/cli/simnet/mod.rs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 47ac27ed..acb171bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ COPY --from=build /out/ /bin/ WORKDIR /workspace -EXPOSE 8899 8900 8488 +EXPOSE 8899 8900 18488 # Create a shell script that provides default behavior RUN echo '#!/bin/bash\n\ diff --git a/crates/cli/src/cli/simnet/mod.rs b/crates/cli/src/cli/simnet/mod.rs index 81468149..26ec58b3 100644 --- a/crates/cli/src/cli/simnet/mod.rs +++ b/crates/cli/src/cli/simnet/mod.rs @@ -79,9 +79,16 @@ pub async fn handle_start_local_surfnet_command( let config = cmd.surfpool_config(airdrop_addresses); let studio_binding_address = config.studio.get_studio_base_url(); - let rpc_url = format!("http://{}", config.rpc.get_rpc_base_url()); - let ws_url = format!("ws://{}", config.rpc.get_ws_base_url()); - let studio_url = format!("http://{}", studio_binding_address); + + // Allow overriding public-facing URLs via environment variables + // This is useful when running behind a reverse proxy (e.g., Caddy, nginx) + let rpc_url = std::env::var("SURFPOOL_PUBLIC_RPC_URL") + .unwrap_or_else(|_| format!("http://{}", config.rpc.get_rpc_base_url())); + let ws_url = std::env::var("SURFPOOL_PUBLIC_WS_URL") + .unwrap_or_else(|_| format!("ws://{}", config.rpc.get_ws_base_url())); + let studio_url = std::env::var("SURFPOOL_PUBLIC_STUDIO_URL") + .unwrap_or_else(|_| format!("http://{}", studio_binding_address)); + let graphql_query_route_url = format!("{}/workspace/v1/graphql", studio_url); let rpc_datasource_url = config.simnets[0].get_sanitized_datasource_url();