Add minimal proxy capabilities to dioxus serve
This adds an MVP of some proxying capabilities to the `dioxus serve` server. The config is similar to that of `trunk serve`: the user can specify one or more proxy backends under `[[web.proxy]]` in Dioxus.toml, and the server will intercept requests targeted at the _path_ of that configured backend and forward them to the backend server. Example ------- For example, if the dev server is serving on port 8080 with this config: ``` [[web.proxy]] backend = "http://localhost:9000/api" ``` then requests to http://localhost:8080/api, http://localhost:8080/api/ and http://localhost:8080/api/any-subpath to be forwarded to the respective paths on http://localhost:9000. This PR doesn't handle path rewriting or anything yet but it would be fairly simple to add in future if anyone needs it.
This commit is contained in:
7 files changed
+240
-12
No files matched your search
@@ -119,6 +119,16 @@ Only include resources at `Dev` mode.
|
||||
]
|
||||
```
|
||||
|
||||
### Web.Proxy
|
||||
|
||||
Proxy requests matching a path to a backend server.
|
||||
|
||||
1. ***backend*** - the URL to the backend server.
|
||||
```
|
||||
backend = "http://localhost:8000/api/"
|
||||
```
|
||||
This will cause any requests made to the dev server with prefix /api/ to be redirected to the backend server at http://localhost:8000. The path and query parameters will be passed on as-is (path rewriting is not currently supported).
|
||||
|
||||
## Config example
|
||||
|
||||
```toml
|
||||
@@ -168,4 +178,7 @@ style = []
|
||||
|
||||
# Javascript code file
|
||||
script = []
|
||||
|
||||
[[web.proxy]]
|
||||
backend = "http://localhost:8000/api/"
|
||||
```
|
||||
Reference in new issue
Block a user