New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LocalDir not working as shown in the examples. #846
Comments
Hello @voxeljorge, Thank you for bringing this. To compile the wasm file into your GOARCH=wasm GOOS=js go build -o /tmp/goappweb/web/app.wasm . I agree that the documentation could do with more clarity on this matter. I'll work on updating it to include this information. Thank you for pointing this out, and please don't hesitate to reach out if you encounter any more issues or have additional suggestions! |
Hm this is what I did, I have compiled
I think the issue is that somehow |
Ahh I see now, you mean that I need a In the screenshot it looks like the browser is attempting to load content from |
The following change to the original code here seems to get this working: package main
import (
"log"
"net/http"
"github.com/maxence-charriere/go-app/v9/pkg/app"
)
type hello struct {
app.Compo
}
func (h *hello) Render() app.UI {
return app.H1().Text("Hello World!")
}
type localDir struct {
http.Handler
}
func (l *localDir) Package() string {
return ""
}
func (l *localDir) Static() string {
return ""
}
func (l *localDir) AppWASM() string {
return "/web/app.wasm"
}
func newLocalDir(rootdir string) app.ResourceProvider {
return &localDir{http.StripPrefix("/web", http.FileServer(http.Dir(rootdir)))}
}
func main() {
app.Route("/", &hello{})
app.RunWhenOnBrowser()
http.Handle("/", &app.Handler{
Name: "Hello",
Description: "An Hello World! example",
Resources: newLocalDir("/tmp/goappweb"),
})
if err := http.ListenAndServe(":8000", nil); err != nil {
log.Fatal(err)
}
} |
I also never got |
From the documentation it seems
LocalDir
is intended to allow you to specify some directory on the local filesystem to serve underweb/
for static assets. There is an example for this showing/tmp/web
as an example destination but this does not seem to work. Here's mymain.go
:I ran the following to build the app:
mkdir -p /tmp/goappweb GOARCH=wasm GOOS=js go build -o /tmp/goappweb/app.wasm .
Here's a screenshot of the result in my browser.
The text was updated successfully, but these errors were encountered: