16 releases
new 0.6.3 | Feb 8, 2025 |
---|---|
0.6.1 | Dec 18, 2024 |
0.6.0-alpha.5 | Nov 16, 2024 |
0.5.6 | Jul 18, 2024 |
0.5.0 | Mar 28, 2024 |
#215 in Configuration
21,535 downloads per month
Used in 54 crates
(13 directly)
14KB
124 lines
dioxus-cli-config
A crate that provides key/value names and types for configuring Dioxus applications at runtime.
This crate exists for us to very cleanly define the exact fields we want to pass down to Dioxus applications at runtime but without exposing the entire config object.
This leads to faster compile times, smaller binaries, and a clearer distinction between the config and the application.
lib.rs
:
Dioxus CLI configuration
This crate exposes the various configuration options that the Dioxus CLI sets when running the application during development.
Note that these functions will return a different value when running under the CLI, so make sure not to rely on them when running in a production environment.
Constants
The various constants here are the names of the environment variables that the CLI sets. We recommend using the functions in this crate to access the values of these environment variables indirectly.
The CLI uses this crate and the associated constants to set the environment variables, but as a consumer of the CLI, you would want to read the values of these environment variables using the provided functions.
Example Usage
We recommend using the functions here to access the values of the environment variables set by the CLI.
For example, you might use the fullstack_address_or_localhost
function to get the address that
the CLI is requesting the application to be served on.
async fn launch_axum(app: axum::Router<()>) {
// Read the PORT and ADDR environment variables set by the CLI
let addr = dioxus_cli_config::fullstack_address_or_localhost();
// Bind to the address and serve the application
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
axum::serve(listener, app.into_make_service())
.await
.unwrap();
}
Stability
The values that these functions return are not guaranteed to be stable between patch releases of Dioxus. At any time, we might change the values that the CLI sets or the way that they are read.
We also don't guarantee the stability of the env var names themselves. If you want to rely on a particular env var, use the defined constants in your code.
Dependencies
~215KB