-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
More control over frontend #2007
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
Comments
I haven't thought too hard about this, and I'm sure @stffabi would be able to provide a better response but I'm thinking we could abstract the current assets handler from the code and put it behind an interface. That way you can provide your own handler. The one caveat, I guess, is how this would work in Dev mode. You'd have to forgo the use of Vite, but it sounds like that's the desired outcome. |
I'm not sure we really need another abstraction for that. Basically setting the I still think everything should be in place to support that, but since it's more of an advanced topic, it needs some changes in how your Wails project is setup compared to a default Wails project and comes with some drawbacks in the Dev mode experience The following example (wails.json and main.go) gives one full control over the Assets and allows everything to be handled by the wails.json {
"name": "demo",
"outputfilename": "demo",
"wailsjsdir": "./build/trash",
"author": {
"name": "stffabi",
"email": "stffabi@users.noreply.github.com"
}
} main.go package main
import (
"net/http"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
)
func main() {
// Create an instance of the app structure
app := NewApp()
// Create application with options
err := wails.Run(&options.App{
Title: "mholt",
Width: 1024,
Height: 768,
AssetsHandler: http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Content of: " + r.RequestURI))
w.WriteHeader(http.StatusOK)
},
),
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
OnStartup: app.startup,
Bind: []interface{}{
app,
},
})
if err != nil {
println("Error:", err.Error())
}
} As @leaanthony already mentioned the Regarding your issues @mholt
I suspect it failed in your case during
I would guess that comes from the frontend build process, and from the frontend framework that is used. That would be need to be changed there. In the demo above, one basically skips all frontend build process etc. ImprovementsI see the following places for improvements.
|
It looks like it's set to "auto" -- would that do it? I tried removing it and unfortunately still get the error.
It's vanilla JS... no frontend framework or build process. I'm boring like that. Maybe exposing the frontend dev server (that serves its assets) as an http.Handler value could be useful, if we wanted to provide our own, then we could still invoke the internal logic when we need to. |
If you have initialised the project with Did you try to update your wails.json according to my example above? Basically removing all those Would you mind sharing your Wails.json and your main.go, maybe that would make it easier to directly helping you to setup the project?
I'm not sure if this would help in this case, since the error of the missing Nevertheless we could however as I've already shortly mentioned on Slack, add an AssetsMiddleware in form of This is pretty straight forward and should give plenty of flexibility for such cases. I've already a local branch with that support ready. |
@stffabi Ahh, right, I forgot about Vite. You are right, if I remove all the I also need to change Mostly little things. But I can now evaluate templates server-side on my Upon saving a file:
Makes sense, so I add Thanks to your help I think I'm up and running. But it's not ideal. This sounds great though:
^ That'd probably be my favorite plan! :) |
Glad you got up and running in your custom setup. Obviously workarounds are just that. If we were to make a significant change like adding a middleware handler, based on your experience, what would that look like? Are there any more little things that would need to change or be considered? The last thing I want to do is hack in a solution, so let's consider this holistically and nail it! :-) |
Great you got it working. I have a branch ready with the middleware, which we could use as discussion base. |
@stffabi Oh perfect. I'd love to test a PR. @leaanthony I think @stffabi's API would work: wrapping a handler in another handler. I just need a handler I can call if/when I want to. |
@stffabi Awesome! Checking it out now. |
This has been working great for me for the last ~week, thank you! |
Will be doing a release tonight hopefully |
Is your feature request related to a problem? Please describe.
All of my frontend pages (on an existing project) need server-side template processing (I use Go's
text/template
andhtml/template
packages), including index.html. Thus I need to be able to render them in my own ServeHTTP, not a built-in handler implementation.Describe the solution you'd like
I'm not sure the best solution as I don't know enough about the internals, but maybe a way that my own http.Handler can serve all the assets instead of as a "fallback" would be enough. Then I could use index.html and wouldn't need to rewrite things (but could if I wanted to).
Describe alternatives you've considered
My first attempt was to set
Assets
to nil in the app options and set anAssetsHandler
to my own HTTP handler, but the built-in handler still magically takes over. Maybe it finds the embedded FS on its own? Anyway, I was thinking I could skirt around the built-in handler if the index.html file 404'ed, thus calling my AssetsHandler, as long as I make sure every link goes to a page that doesn't exist. I just have to rewrite the URL server-side, internally. No problem.But I'm having a bit of trouble with this, since index.html is a required asset:
This means I can't rewrite requests to
/
or/index.html
to, say_index.html
ormyindex.html
because the program won't even build without a real index.html file. Which means I can't serve it using my own handler, and can't evaluate templates server-side.Additional context
Thank you for Wails, it's quite awesome :D
The text was updated successfully, but these errors were encountered: