Skip to content

Commit

Permalink
fix(NET-244): use static http server port on windows (#471)
Browse files Browse the repository at this point in the history
* fix(NET-244): use static http server port on windows

* fix(NET-244): remove unnecessary named import

* fix(NET-244): rename vars to follow convention
  • Loading branch information
Aceix authored Jun 28, 2023
1 parent 3098e88 commit 3ef4648
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 45 deletions.
22 changes: 15 additions & 7 deletions functions/httpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"
"net/http"
"runtime"
"strings"
"sync"

Expand All @@ -22,19 +23,26 @@ type Network struct {
Server config.Server
}

const DefaultHttpServerPort = "18095"
const DefaultHttpServerAddr = "127.0.0.1"

func HttpServer(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
if config.Netclient().DisableGUIServer {
return
}
port, err := ncutils.GetFreeTCPPort()
if err != nil {
logger.Log(0, "failed to get free port", err.Error())
logger.Log(0, "unable to start http server", "exiting")
logger.Log(0, "netclient-gui will not be available")
return
port := DefaultHttpServerPort
if runtime.GOOS != "windows" {
p, err := ncutils.GetFreeTCPPort()
if err != nil {
logger.Log(0, "failed to get free port", err.Error())
logger.Log(0, "unable to start http server", "exiting")
logger.Log(0, "netclient-gui will not be available")
return
}
port = p
}
config.SetGUI("127.0.0.1", port)
config.SetGUI(DefaultHttpServerAddr, port)
config.WriteGUIConfig()

router := SetupRouter()
Expand Down
103 changes: 71 additions & 32 deletions gui/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions gui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package main
import (
"embed"
"log"
"runtime"

"github.com/gravitl/netclient/config"
"github.com/gravitl/netclient/functions"
"github.com/gravitl/netmaker/logger"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
Expand All @@ -22,15 +24,17 @@ var appIcon = GetFileAsBytes("./appicon.png")

var version = "v0.20.3"

var url = "http://127.0.0.1:8090"
var url = "http://" + functions.DefaultHttpServerAddr + ":" + functions.DefaultHttpServerPort

func main() {
log.Println("staring netclient gui version: ", version) // temp.. version should be displayed in about dialog
http, err := config.ReadGUIConfig()
if err != nil {
logger.FatalLog("error reading gui config", err.Error())
if runtime.GOOS != "windows" {
http, err := config.ReadGUIConfig()
if err != nil {
logger.FatalLog("error reading gui config", err.Error())
}
url = "http://" + http.Address + ":" + http.Port
}
url = "http://" + http.Address + ":" + http.Port
// Create an instance of the guiApp structure
guiApp := NewApp()
guiApp.GoGetNetclientConfig()
Expand Down Expand Up @@ -68,7 +72,7 @@ func main() {
}

// Create application with options
err = wails.Run(appOptions)
err := wails.Run(appOptions)

if err != nil {
println("Error:", err.Error())
Expand Down

0 comments on commit 3ef4648

Please sign in to comment.