From 5e79b7d4d1f3c2b35239df8307740bc8e4754751 Mon Sep 17 00:00:00 2001 From: Benny Daon Date: Tue, 2 Jul 2024 17:03:52 +0300 Subject: [PATCH] Removing WEBEXEC_SERVER_URL --- README.md | 4 ++-- docs/conf.md | 3 ++- go.mod | 2 +- go.sum | 4 ++-- httpserver/http.go | 15 +++++---------- httpserver/http_test.go | 1 - 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 59a8941..ec6b2c3 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,8 @@ $ go install ./... webexec has a signlaing server that listen for connection request on ports 7777. By default it listens only for localhost. To -open webexec to the world set `WEBEXEC_SERVER_URL` to the the server's -public URL, default is `http://localhost:7777`. +open webexec to the world set the http_server under [net] in the config file +to 0.0.0.0:7777. Once communication is established, WebRTC uses UDP ports with a default range of 60000-61000. diff --git a/docs/conf.md b/docs/conf.md index 26e6e70..b2b0aae 100644 --- a/docs/conf.md +++ b/docs/conf.md @@ -16,7 +16,8 @@ run. ### net -- http_server: The address the https server listen on. default: `0.0.0.0:7777` +- http_server: The address the https server listen on. default: `127.0.0.1:7777` +set to 0.0.0.0:7777 to listen on all interfaces - udp_port_min: the minimum UDP port to use - udp_port_max: the maximum UDP port to use diff --git a/go.mod b/go.mod index c14deb2..7556594 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/dchest/uniuri v1.2.0 github.com/fatih/color v1.17.0 github.com/google/uuid v1.3.1 - github.com/gorilla/websocket v1.4.2 + github.com/gorilla/websocket v1.5.1 github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 github.com/pelletier/go-toml v1.9.3 github.com/pion/webrtc/v3 v3.2.32 diff --git a/go.sum b/go.sum index ea7b85b..f2aa418 100644 --- a/go.sum +++ b/go.sum @@ -45,8 +45,8 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= -github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA= github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8= diff --git a/httpserver/http.go b/httpserver/http.go index 1cdb340..a1ff133 100644 --- a/httpserver/http.go +++ b/httpserver/http.go @@ -7,7 +7,6 @@ import ( "io" "io/ioutil" "net/http" - "os" "time" "github.com/google/uuid" @@ -30,7 +29,6 @@ type ConnectHandler struct { authBackend AuthBackend peerConf *peers.Conf logger *zap.SugaredLogger - address AddressType sessions map[uuid.UUID]*peers.Peer } @@ -44,17 +42,10 @@ type ConnectRequest struct { func NewConnectHandler( backend AuthBackend, conf *peers.Conf, logger *zap.SugaredLogger) *ConnectHandler { - adress := os.Getenv("WEBEXEC_SERVER_URL") - if adress == "" { - adress = "http://localhost:7777" - } - logger.Infof("Using %s as server address", adress) - return &ConnectHandler{ authBackend: backend, peerConf: conf, logger: logger, - address: AddressType(adress), sessions: make(map[uuid.UUID]*peers.Peer), } } @@ -167,7 +158,11 @@ func (h *ConnectHandler) HandleOffer(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/sdp") w.Header().Set("ETag", fmt.Sprintf("%x", time.Now().Unix())) - url := fmt.Sprintf("%s/candidates/%s", h.address, sessionID) + scheme := r.Header.Get("X-Forwarded-Proto") + if scheme == "" { + scheme = "http" // Assume http if header is missing. + } + url := fmt.Sprintf("%s://%s/candidates/%s", scheme, r.Host, sessionID) w.Header().Set("Location", url) w.WriteHeader(http.StatusCreated) w.Write([]byte(answer.SDP)) diff --git a/httpserver/http_test.go b/httpserver/http_test.go index de64bb6..3bf4f99 100644 --- a/httpserver/http_test.go +++ b/httpserver/http_test.go @@ -354,7 +354,6 @@ func FuncTestOffer(t *testing.T) { authBackend: a, peerConf: conf, logger: logger, - address: AddressType("127.0.0.1:7777"), } h.HandleOffer(w, req) require.Equal(t, http.StatusCreated, w.Code)