[windows] improvements to dev

This commit is contained in:
Lea Anthony 2023-11-27 21:24:58 +11:00
commit 8242834fbd
No known key found for this signature in database
GPG key ID: 33DAF7BB90A58405
4 changed files with 37 additions and 14 deletions

View file

@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"math/rand"
"net"
"net/http"
"net/http/httptest"
"net/http/httputil"
@ -99,28 +100,25 @@ func NewAssetServer(options *Options, servingFromDisk bool, logger *slog.Logger,
if result.devServerURL != "" {
logger.Info("Using External DevServer", "url", result.devServerURL)
// Parse devServerURL into url.URL
devserverURL, err := url.Parse(result.devServerURL)
devServerURL, err := url.Parse(result.devServerURL)
if err != nil {
return nil, err
}
result.wsHandler = httputil.NewSingleHostReverseProxy(devserverURL)
err = result.checkDevServerURL()
err = result.checkDevServerURL(devServerURL)
if err != nil {
return nil, err
}
result.wsHandler = httputil.NewSingleHostReverseProxy(devServerURL)
}
return result, nil
}
func (d *AssetServer) checkDevServerURL() error {
req, err := http.NewRequest("OPTIONS", "/", nil)
func (d *AssetServer) checkDevServerURL(devServerURL *url.URL) error {
// Open a connection to the devserver URL
hostPort := devServerURL.Hostname() + ":" + devServerURL.Port()
_, err := net.DialTimeout("tcp", hostPort, 1*time.Second)
if err != nil {
return err
}
w := httptest.NewRecorder()
d.wsHandler.ServeHTTP(w, req)
if w.Code != http.StatusNoContent {
return fmt.Errorf("unable to connect to external server: %s. Please check it's running", d.devServerURL)
return fmt.Errorf("unable to connect to dev server: %s. Please check it's running", d.devServerURL)
}
return nil
}

View file

@ -3,10 +3,13 @@ package commands
import (
"fmt"
"net"
"net/url"
"strconv"
"time"
)
type ToolCheckPortOptions struct {
URL string `name:"u" description:"URL to check"`
Host string `name:"h" description:"Host to check" default:"localhost"`
Port int `name:"p" description:"Port to check"`
}
@ -26,8 +29,24 @@ func isPortOpen(ip string, port int) bool {
}
func ToolCheckPort(options *ToolCheckPortOptions) error {
if options.Port == 0 {
return fmt.Errorf("please use the -p flag to specify a port")
if options.URL != "" {
// Parse URL
u, err := url.Parse(options.URL)
if err != nil {
return err
}
options.Host = u.Hostname()
options.Port, err = strconv.Atoi(u.Port())
if err != nil {
return err
}
} else {
if options.Port == 0 {
return fmt.Errorf("please use the -p flag to specify a port")
}
if !isPortOpen(options.Host, options.Port) {
return fmt.Errorf("port %d is not open on %s", options.Port, options.Host)
}
}
if !isPortOpen(options.Host, options.Port) {
return fmt.Errorf("port %d is not open on %s", options.Port, options.Host)

View file

@ -404,11 +404,16 @@ tasks:
dev:frontend:
summary: Runs the frontend in development mode
dir: frontend
deps:
- task: install:frontend:deps
cmds:
- npm run dev
dev:
summary: Runs the application in development mode
preconditions:
- sh: wails3 tool checkport -u {{ "\"$WAILS_DEVSERVER_URL\"" }}
msg: "Looks like the devserver isn't available. Please ensure you have run `wails3 task dev:frontend` in another terminal."
cmds:
- wails3 tool watcher -path {{ "{{.PATH}}" }} -preexec {{ "\"{{.PREEXEC}}\""}} {{ "{{.PREWAIT}}" }} -postexec {{ "\"{{.POSTEXEC}}\"" }} -ignorefiles {{ "{{.IGNOREFILES}}" }} -ignoredirs {{ "{{.IGNOREDIRS}}" }} -ignoreextensions {{ "{{.IGNOREEXTENSIONS}}" }} -exec {{ "\"{{.EXEC}}\"" }} -debounce {{ "{{.DEBOUNCE}}" }}
vars:

View file

@ -76,7 +76,8 @@ func New(appOptions Options) *App {
srv, err := assetserver.NewAssetServer(opts, false, result.Logger, wailsruntime.RuntimeAssetsBundle, result.isDebugMode, NewMessageProcessor(result.Logger))
if err != nil {
result.fatal(err.Error())
result.Logger.Error("Fatal error in application initialisation: " + err.Error())
os.Exit(1)
}
// Pass through the capabilities