@@ -155,21 +155,31 @@ private Conductor(Builder builder) {
155155 String appName = dbosExecutor .appName ();
156156 Objects .requireNonNull (appName , "App Name must not be null to use Conductor" );
157157
158- String domain = builder .domain ;
159- if (domain == null ) {
158+ var hostname = builder .domain ;
159+ if (hostname == null ) {
160160 String dbosDomain = System .getenv ("DBOS_DOMAIN" );
161161 if (dbosDomain == null || dbosDomain .trim ().isEmpty ()) {
162- domain = "wss:// cloud.dbos.dev" ;
162+ hostname = "cloud.dbos.dev" ;
163163 } else {
164- domain = "wss://" + dbosDomain .trim ();
164+ hostname = dbosDomain .trim ();
165165 }
166- domain += "/conductor/v1alpha1" ;
167166 } else {
168167 // ensure there is no trailing slash
169- domain = domain .replaceAll ("/$" , "" );
168+ hostname = hostname .replaceAll ("/$" , "" );
170169 }
171170
172- this .url = domain + "/websocket/" + appName + "/" + builder .conductorKey ;
171+ // Determine protocol based on hostname (use ws for localhost, wss for others)
172+ boolean isLocalHost =
173+ "localhost" .equals (hostname )
174+ || hostname .startsWith ("localhost:" )
175+ || "127.0.0.1" .equals (hostname )
176+ || hostname .startsWith ("127.0.0.1:" );
177+ var protocol = isLocalHost ? "ws" : "wss" ;
178+
179+ this .url =
180+ String .format (
181+ "%s://%s/conductor/v1alpha1/websocket/%s/%s" ,
182+ protocol , hostname , appName , builder .conductorKey );
173183
174184 this .pingPeriodMs = builder .pingPeriodMs ;
175185 this .pingTimeoutMs = builder .pingTimeoutMs ;
0 commit comments