Crate dioxus_cli_config

Source
Expand description
Build web, desktop, and mobile apps with a single codebase.

§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.