set default subdomain and bootstrap based by portal url
Kim committed
Nov 19, 2025 at 11:58 UTC
030af570f8f357b7b28b61b470c58983dcc4fee6
2 files changed
+48
-3
cmd/relay-server/main.go
+4
-3
@@ -32,15 +32,16 @@ func main() {
32
33
defaultPortalURL := strings.TrimSuffix(os.Getenv("PORTAL_URL"), "/")
34
if defaultPortalURL == "" {
35
- defaultPortalURL = "localhost:4017"
35
+ // Prefer explicit scheme for localhost so downstream URL building is unambiguous
36
+ defaultPortalURL = "http://localhost:4017"
37
}
38
defaultSubdomain := os.Getenv("PORTAL_SUBDOMAIN_URL")
39
if defaultSubdomain == "" {
39
- defaultSubdomain = "*.localhost:4017"
40
+ defaultSubdomain = sdk.DefaultSubdomainPattern(defaultPortalURL)
41
}
42
defaultBootstraps := os.Getenv("BOOTSTRAP_URIS")
43
if defaultBootstraps == "" {
43
- defaultBootstraps = "ws://localhost:4017/relay"
44
+ defaultBootstraps = sdk.DefaultBootstrapFrom(defaultPortalURL)
45
}
46
47
var flagBootstrapsCSV string
sdk/utils.go
+44
@@ -268,3 +268,47 @@ func StripPort(s string) string {
268
}
269
return s
270
}
271
+
272
+// DefaultSubdomainPattern builds a wildcard subdomain pattern from a base portal URL or host.
273
+// Examples:
274
+// - "https://portal.example.com" -> "*.portal.example.com"
275
+// - "portal.example.com" -> "*.portal.example.com"
276
+// - "localhost:4017" -> "*.localhost:4017"
277
+// - "" -> "*.localhost:4017"
278
+func DefaultSubdomainPattern(base string) string {
279
+ base = strings.TrimSpace(strings.TrimSuffix(base, "/"))
280
+ if base == "" {
281
+ return "*.localhost:4017"
282
+ }
283
+ host := StripWildCard(StripScheme(base))
284
+ if host == "" {
285
+ return "*.localhost:4017"
286
+ }
287
+ // Avoid doubling wildcard if provided accidentally
288
+ if strings.HasPrefix(host, "*.") {
289
+ return host
290
+ }
291
+ return "*." + host
292
+}
293
+
294
+// DefaultBootstrapFrom derives a websocket bootstrap URL from a base portal URL or host.
295
+// It prefers NormalizePortalURL for consistent mapping and falls back to localhost.
296
+// Examples:
297
+// - "https://portal.example.com" -> "wss://portal.example.com/relay"
298
+// - "http://portal.example.com" -> "ws://portal.example.com/relay"
299
+// - "localhost:4017" -> "wss://localhost:4017/relay"
300
+// - "" -> "ws://localhost:4017/relay"
301
+func DefaultBootstrapFrom(base string) string {
302
+ base = strings.TrimSpace(base)
303
+ if base == "" {
304
+ return "ws://localhost:4017/relay"
305
+ }
306
+ if u, err := NormalizePortalURL(base); err == nil && u != "" {
307
+ return u
308
+ }
309
+ host := StripScheme(strings.TrimSuffix(base, "/"))
310
+ if host == "" {
311
+ return "ws://localhost:4017/relay"
312
+ }
313
+ return "ws://" + host + "/relay"
314
+}