mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 16:26:38 +00:00
[relay] Use instanceURL instead of Exposed address. (#4905)
Replaces string-based exposed address handling with URL-based InstanceURL() (type url.URL) across relay/server and relay/healthcheck; adds SchemeREL/SchemeRELS constants; updates getInstanceURL to return *url.URL with scheme and TLS validation; adjusts WS dialing and health-check logic to use URL fields.
This commit is contained in:
@@ -3,22 +3,22 @@ package healthcheck
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"net/url"
|
||||
|
||||
"github.com/coder/websocket"
|
||||
|
||||
"github.com/netbirdio/netbird/relay/server"
|
||||
"github.com/netbirdio/netbird/shared/relay"
|
||||
)
|
||||
|
||||
func dialWS(ctx context.Context, address string) error {
|
||||
addressSplit := strings.Split(address, "/")
|
||||
func dialWS(ctx context.Context, address url.URL) error {
|
||||
scheme := "ws"
|
||||
if addressSplit[0] == "rels:" {
|
||||
if address.Scheme == server.SchemeRELS {
|
||||
scheme = "wss"
|
||||
}
|
||||
url := fmt.Sprintf("%s://%s%s", scheme, addressSplit[2], relay.WebSocketURLPath)
|
||||
wsURL := fmt.Sprintf("%s://%s%s", scheme, address.Host, relay.WebSocketURLPath)
|
||||
|
||||
conn, resp, err := websocket.Dial(ctx, url, nil)
|
||||
conn, resp, err := websocket.Dial(ctx, wsURL, nil)
|
||||
if resp != nil {
|
||||
defer func() {
|
||||
if resp.Body != nil {
|
||||
|
||||
Reference in New Issue
Block a user