wails: Dev build uses ExternalAssetHandler, but production build does not?

Description

When I run wails dev and my frontend navigates to /gallery/, my external assets handler rewrites the request to serve /gallery/index.html. However, with the exact same code compiled with wails build, the exact same page load yields 500 Internal Server Error.

To Reproduce

Here’s my code:

func (a *App) Run() error {
	return wails.Run(&options.App{
		Title:     "Timelinize",
		Width:     1200,
		Height:    800,
		Frameless: true,
		AssetServer: &assetserver.Options{
			Assets:     a.frontend,
			Middleware: a.StaticWebsiteMiddleware,
		},
		OnStartup: func(ctx context.Context) { a.ctx = ctx },
		Bind:      []any{a},
	})
}

Notice I set up a custom AssetServer with my own Middleware. The Middleware basically determines whether the request needs to be rewritten or have server-side templates evaluated, and if not, it passes the request to the next handler (wails).

Anyway, this all works great with wails dev:

DEB | [ExternalAssetHandler] Loading 'http://localhost:3000/gallery/'

But running the same program from wails build produces:

ERR | [AssetHandler] Unable to load file 'gallery/': open gallery/: invalid argument

It seems to me that the production build is not using ExternalAssetHandler.

Expected behaviour

I’d expect wails dev and wails build programs to run the same in this regard.

Screenshots

(Probably not applicable, since it’s text logs. The UI just crashes with ā€œInternal server errorā€

Attempted Fixes

I’m not sure what to try yet. This is a new feature, so I’m not surprised if I’m either using it wrong or there’s a little bug. šŸ› šŸ™‚

System Details

Wails CLI v2.2.0

Scanning system - Please wait (this may take a long time)...Done.

System
------
OS:             Pop!_OS
Version:        22.04
ID:             pop
Go Version:     go1.19.1
Platform:       linux
Architecture:   amd64

Wails
------
Version:                v2.2.0
Package Manager:        apt

Dependency      Package Name            Status          Version
----------      ------------            ------          -------
*docker         docker.io               Available       20.10.12-0ubuntu4
gcc             build-essential         Installed       11.3.0
libgtk-3        libgtk-3-dev            Installed       3.24.33-1ubuntu2
libwebkit       libwebkit2gtk-4.0-dev   Installed       2.38.2-0ubuntu0.22.04.2
npm             npm                     Installed       8.5.1~ds-1
*nsis           nsis                    Available       3.08-2
pkg-config      pkg-config              Installed       0.29.2

* - Optional Dependency

Diagnosis
---------
Your system is ready for Wails development!
Optional package(s) installation details: 
  - docker: sudo apt install docker.io
  - nsis: sudo apt install nsis

Additional context

Thank you again for Wails, it’s awesome!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

Those ones I guess šŸ˜‰ Ok, we can spend the effort supporting 2.36 instead šŸ‘

Already on it and almost finished šŸ˜€

Seems like this commit https://github.com/WebKit/WebKit/commit/a7bf4e2c5f14ef2cac00321362b0c38ffadab1c7 added the RedirectionAPI for cocoa but it’s still not available in macOS. And the API is also missing for WebKit2GTK. According to that commit we would need to handle http Redirects in a special way by calling another API to finish the request.

Nice one @stffabi! Looks like 2.36+ would help on a number of fronts. I’ll see if that’s something I can look at this week. Perhaps #2044 could help for fallback functionality if it’s not there. I’m hoping it’s not an all or nothing thing…

Thanks for bringing this up @mholt.

The ExternalAssetHandler is something very specialised only for the dev mode. It handles all the integration with the external dev server and proxies requests over to it. So the final destination is a full featured web server and can handle a request to /gallery/ by serving the index.html there.

When using the production build, there’s an internal ā€˜dummy’ WebServer which serves the content. As such it has some missing features, but step by step we are adding more to it. Recently we added support for range requests and this issue is also a missing functionality.

I already have a branch ready for this, but don’t know if I will finish it today.

Those ones I guess šŸ˜‰ Ok, we can spend the effort supporting 2.36 instead šŸ‘

Oh, thanks. I didn’t realize it was only for dev mode. I would definitely expect that my dev mode asset server is the same as for the production builds

Unfortunately that’s not possible to have them 100% identical at least not without starting a webserver on localhost in production mode and bundle e.g. Vite and start it in production. But not having to start a webserver is a main feature of Wails. There are cases where a webserver on localhost might not be a problem, but e.g. for commercial products this might be problematic. A company might not like to have the whole frontend and the full backend-frontend communication being exposed.

Maybe once we could write a technical whitepaper with all the technical details. More people asked about this lately.

My program won’t work if it can’t also do rewriting and template evaluation for the frontend files.

The middleware can also be used in production. You can also rewrite the response body there like in dev mode. But there are limitations of what can be used from the request and response, see the feature matrix in AssetServer. What do you mean by rewriting? Do you mean http.Redirects?

Oh, thanks. I didn’t realize it was only for dev mode. I would definitely expect that my dev mode asset server is the same as for the production builds. My program won’t work if it can’t also do rewriting and template evaluation for the frontend files.

No rush on pushing the branch, I can use dev mode for now. But hopefully in the future I can also have it work with wails build. šŸ˜€