Skip to content

Commit

Permalink
Correctly compute 'startURL' when using a frontend development server. (
Browse files Browse the repository at this point in the history
#3299)

* Fix computing 'startURL' when 'FRONTEND_DEVSERVER_URL' is present.

* Respect provided URL when computing 'startURL' and 'FRONTEND_DEVSERVER_URL' is present.

* Update changelog.

* Correctly produce absolute URI in 'GetStartURL' when input is provided.
  • Loading branch information
joshdrake authored Mar 8, 2024
1 parent 4467a1f commit f38532b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
1 change: 1 addition & 0 deletions mkdocs-website/docs/en/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix failing Windows build due to unknown option by [thomas-senechal](https://github.com/thomas-senechal) in PR [#3208](https://github.com/wailsapp/wails/pull/3208)
- Fix wrong baseURL when open window twice by @5aaee9 in PR [#3273](https://github.com/wailsapp/wails/pull/3273)
- Fix ordering of if branches in `WebviewWindow.Restore` method by [@fbbdev](https://github.com/fbbdev) in [#3279](https://github.com/wailsapp/wails/pull/3279)
- Correctly compute `startURL` across multiple `GetStartURL` invocations when `FRONTEND_DEVSERVER_URL` is present. [#3299](https://github.com/wailsapp/wails/pull/3299)

### Changed

Expand Down
27 changes: 10 additions & 17 deletions v3/internal/assetserver/assetserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,19 @@ func GetStartURL(userURL string) (string, error) {
}
port := parsedURL.Port()
if port != "" {
baseURL.Host = net.JoinHostPort(baseURL.Host, port)
baseURL.Host = net.JoinHostPort(baseURL.Hostname(), port)
startURL = baseURL.String()
}
} else {
if userURL != "" {
// parse the url
parsedURL, err := url.Parse(userURL)
if err != nil {
return "", fmt.Errorf("Error parsing URL: " + err.Error())
}
if parsedURL.Scheme == "" {
startURL = baseURL.ResolveReference(&url.URL{Path: userURL}).String()
// if the original URL had a trailing slash, add it back
if strings.HasSuffix(userURL, "/") && !strings.HasSuffix(startURL, "/") {
startURL = startURL + "/"
}
} else {
startURL = userURL
}
}

if userURL != "" {
parsedURL, err := baseURL.Parse(userURL)
if err != nil {
return "", fmt.Errorf("Error parsing URL: " + err.Error())
}

startURL = parsedURL.String()
}

return startURL, nil
}

0 comments on commit f38532b

Please sign in to comment.