Expand description
§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.
Constants§
- ALWAYS_
ON_ TOP_ ENV - APP_
TITLE_ ENV - ASSET_
ROOT_ ENV - CLI_
ENABLED_ ENV - DEVSERVER_
IP_ ENV - DEVSERVER_
PORT_ ENV - SERVER_
IP_ ENV - SERVER_
PORT_ ENV - SESSION_
CACHE_ DIR
Functions§
- always_
on_ top - Check if the application should forced to “float” on top of other windows.
- android_
session_ cache_ dir - The session cache directory for android
- app_
title - Get the title of the application, usually set by the Dioxus.toml.
- base_
path - Get the path where the application will be served from.
- devserver_
raw_ addr - Get the address of the devserver for use over a raw socket
- devserver_
ws_ endpoint - Get the address of the devserver for use over a websocket
- fullstack_
address_ or_ localhost - Get the full address that the server should listen on.
- is_
cli_ enabled - Check if the CLI is enabled when running the application.
- server_
ip - Get the IP that the server should be bound to.
- server_
port - Get the port that the server should listen on.
- session_
cache_ dir - Get the directory where this app can write to for this session that’s guaranteed to be stable between reloads of the same app. This is useful for emitting state like window position and size so the app can restore it when it’s next opened.