mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
[v2] Add support for AssetsHandler (#1325)
* [website] Fix devserver default value doc
* [v2] Add support for AssetsHandler
AssetsHandler is a http.Handler delegate, which gets called
as a fallback for all Non-GET requests and for GET requests
for which the Assets didn’t find the file.
Known Limitations on Linux:
- All requests are GET requests
- No request headers
- No request body
- No response status code, only StatusOK will be returned
- No response headers
Known Limitations on Windows:
- Request body is leaking memory. Seems to be a bug in
WebView2, investigation angoing.
Most of these limitations on Linux will be fixed in the future with
adding support for Webkit2Gtk 2.36.0+.
* [v2, linux] Add response streaming support
The complete response won’t be held anymore in memory and will
be streamed to WebKit2.
Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
This commit is contained in:
@@ -161,6 +161,15 @@ The second, if given, will be executed in the `frontend` directory to build the
|
||||
|
||||
If these 2 keys aren't given, then Wails does absolutely nothing with the frontend. It is only expecting that `embed.FS`.
|
||||
|
||||
### AssetsHandler
|
||||
|
||||
A Wails v2 app can optionally define a `http.Handler` in the `options.App`, which allows hooking into the AssetServer to
|
||||
create files on the fly or process POST/PUT requests.
|
||||
GET requests are always first handled by the `assets` FS. If the FS doesn't find the requested file the request will be
|
||||
forwarded to the `http.Handler` for serving. Any requests other than GET will be directly processed by the `AssetsHandler`
|
||||
if specified.
|
||||
It's also possible to only use the `AssetsHandler` by specifiy `nil` as the `Assets` option.
|
||||
|
||||
## Built in Dev Server
|
||||
|
||||
Running `wails dev` will start the built in dev server which will start a file watcher in your project directory. By
|
||||
|
||||
@@ -30,6 +30,7 @@ func main() {
|
||||
RGBA: &options.RGBA{R: 0, G: 0, B: 0, A: 255},
|
||||
AlwaysOnTop: false,
|
||||
Assets: assets,
|
||||
AssetsHandler: assetsHandler,
|
||||
Menu: app.applicationMenu(),
|
||||
Logger: nil,
|
||||
LogLevel: logger.DEBUG,
|
||||
@@ -221,6 +222,36 @@ Type: \*embed.FS
|
||||
|
||||
The frontend assets to be used by the application. Requires an `index.html` file.
|
||||
|
||||
### AssetsHandler
|
||||
|
||||
Name: AssetsHandler
|
||||
|
||||
Type: \*http.Handler
|
||||
|
||||
The assets handler is a generic `http.Handler` which will be called for any non GET request on the assets server
|
||||
and for GET requests which can not be served from the `assets` because the file is not found.
|
||||
|
||||
| Value | Win | Mac | Lin |
|
||||
| ----------------------------- | --- | --- | --- |
|
||||
| GET | ✅ | ✅ | ✅ |
|
||||
| POST | ✅ | ✅ | ❌ |
|
||||
| PUT | ✅ | ✅ | ❌ |
|
||||
| PATCH | ✅ | ✅ | ❌ |
|
||||
| DELETE | ✅ | ✅ | ❌ |
|
||||
| Request Headers | ✅ | ✅ | ❌ |
|
||||
| Request Body | ✅ | ✅ | ❌ |
|
||||
| Request Body Streaming | ❌ | ❌ | ❌ |
|
||||
| Response StatusCodes | ✅ | ✅ | ❌ |
|
||||
| Response Headers | ✅ | ✅ | ❌ |
|
||||
| Response Body | ✅ | ✅ | ✅ |
|
||||
| Response Body Streaming | ❌ | ❌ | ✅ |
|
||||
|
||||
NOTE: Linux is currently very limited due to targeting a WebKit2GTK Version < 2.36.0. In the future some features will be
|
||||
supported by the introduction of WebKit2GTK 2.36.0+ support.
|
||||
|
||||
NOTE: When used in combination with a Frontend DevServer there might be limitations, eg. Vite serves the index.html
|
||||
on every path, that does not contain a file extension.
|
||||
|
||||
### Menu
|
||||
|
||||
Name: Menu
|
||||
@@ -316,7 +347,7 @@ Defines how the window should present itself at startup.
|
||||
| --------------- | --- | --- | --- |
|
||||
| Fullscreen | ✅ | ✅ | ✅ |
|
||||
| Maximised | ✅ | ✅ | ✅ |
|
||||
| Minimised | ✅ | | ✅ |
|
||||
| Minimised | ✅ | ❌ | ✅ |
|
||||
|
||||
### Bind
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ The project config resides in the `wails.json` file in the project directory. Th
|
||||
"version": "[Project config version]",
|
||||
"outputfilename": "[The name of the binary]",
|
||||
"debounceMS": 100, // The default time the dev server waits to reload when it detects a vhange in assets
|
||||
"devServer": "[Address to bind the wails dev sever to. Default: http://localhost:34115]",
|
||||
"devServer": "[Address to bind the wails dev sever to. Default: localhost:34115]",
|
||||
"appargs": "[Arguments passed to the application in shell style when in dev mode]",
|
||||
"runNonNativeBuildHooks": false, // Defines if build hooks should be run though they are defined for an OS other than the host OS.
|
||||
"postBuildHooks": {
|
||||
|
||||
Reference in New Issue
Block a user