Skip to content

Commit

Permalink
Properly handle prefix="" in CustomProvider()
Browse files Browse the repository at this point in the history
It might be that an app could support either running behind a reverse
proxy or directly. In the latter case, prefix would be "". This modifies
CustomProvider to properly handle that case.

Previously, CustomProvider() would apply this to prefix unconditionally:

	prefix = "/" + strings.Trim(prefix, "/")

Starting with prefix = "", prefix would become "/", making appWASM
"//web/app.wasm". A browser that acted on such a path might erroneously
load, e.g., "http://web/app.wasm".

Now, CustomProvider() only trims and concatenates when prefix != "".

Signed-off-by: W. Michael Petullo <mike@flyn.org>
  • Loading branch information
flyn-org committed Apr 5, 2024
1 parent 4af7476 commit c88eed1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/app/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ func GitHubPages(repoName string) ResourceProvider {
// given prefix.
func CustomProvider(path, prefix string) ResourceProvider {
root := strings.Trim(path, "/")
prefix = "/" + strings.Trim(prefix, "/")

if prefix != "" {
prefix = "/" + strings.Trim(prefix, "/")
}

return localDir{
Handler: http.FileServer(http.Dir(root)),
Expand Down

0 comments on commit c88eed1

Please sign in to comment.