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.
4.8 KiB
Configure Project
This chapter will introduce Dioxus.toml and anatomy the config file.
Structure
We use toml to define some info for dioxus project.
Application
- name - project name & title
- default_platform - which platform target for this project.
change this to
# current support: web, desktop # default: web default_platform = "web"desktop, thedioxus build & servewill default build desktop app. - out_dir - which directory to put the output file; use
dioxus build & service, the output will put at this directory, and theassetswill be also copy to here.out_dir = "dist" - asset_dir - which direcotry to put your
static, assetsfile, cli will automatic copy all file toout_dir, so you can put some resource file in there, likeCSS, JS, Imagefile.asset_dir = "public"
Application.Tools
You can combine different tools with dioxus.
-
binaryen - Use the
binaryentooling suite.# current support: wasm-opt # default: web binaryen = { wasm_opt = true }Use the
wasm_opt = truekey/pair value to activate optimization with wasm-opt. When building onreleaseprofile, Dioxus will runwasm_optwith-Ozoption. -
tailwindcss - Use the
tailwindcssstandalone binary to generate a Tailwind CSS bundle file.tailwindcss = { input = "main.css", config = "tailwind.config.js" }You can set two optional keys :
- input: path of the input CSS file (default value is "public/tailwind.css")
- config: path to the config file for Tailwind (default value is "src/tailwind.config.js")
When building on
releaseprofile, Dioxus will runtailwindcsswith the--minifyoption.Note : Dioxus will automatically include the generated tailwind file in the
index.html
Web.App
Web platform application config:
- title - this value will display on the web page title. like
<title></title>tag.# HTML title tag content title = "dioxus app | ⛺"
Web.Watcher
Web platform dev-server watcher config:
- reload_html - a boolean value; when watcher trigger, regenerate
index.htmlfile.# when watcher trigger, regenerate the `index.html` reload_html = true - watch_path - which files & directories will be watcher monitoring.
watch_path = ["src", "public"]
Web.Resource
Include some CSS Javascript resources into html file.
- style - include some style(CSS) file into html.
style = [ # include from public_dir. "./assets/style.css", # or some asset from online cdn. "https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.css" ] - script - include some script(JS) file into html.
style = [ # include from public_dir. "./assets/index.js", # or some asset from online cdn. "https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.js" ]
Web.Resource.Dev
Only include resources at Dev mode.
- style - include some style(CSS) file into html.
style = [ # include from public_dir. "./assets/style.css", # or some asset from online cdn. "https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.css" ] - script - include some script(JS) file into html.
style = [ # include from public_dir. "./assets/index.js", # or some asset from online cdn. "https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.js" ]
Web.Proxy
Proxy requests matching a path to a backend server.
- backend - the URL to the backend server.
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).
backend = "http://localhost:8000/api/"
Config example
[application]
# App (Project) Name
name = "{{project-name}}"
# Dioxus App Default Platform
# desktop, web, mobile, ssr
default_platform = "web"
# `build` & `serve` dist path
out_dir = "dist"
# resource (public) file folder
asset_dir = "public"
[web.app]
# HTML title tag content
title = "dioxus | ⛺"
[web.watcher]
# when watcher trigger, regenerate the `index.html`
reload_html = true
# which files or dirs will be watcher monitoring
watch_path = ["src", "public"]
# include `assets` in web platform
[web.resource]
# CSS style file
style = []
# Javascript code file
script = []
[web.resource.dev]
# serve: [dev-server] only
# CSS style file
style = []
# Javascript code file
script = []
[[web.proxy]]
backend = "http://localhost:8000/api/"