Files
dioxus/packages/cli-config/src/serve.rs
T
Evan Almloff ffa36a67c3 Forward cli serve settings and make it easier to provide platform config to fullstack (#2521)
* assert that launch never returns for better compiler errors

* fix static generation launch function

* fix web renderer

* pass context providers into server functions

* add an example for FromContext

* clean up DioxusRouterExt

* fix server function context

* fix fullstack desktop example

* forward CLI serve settings to fullstack

* re-export serve config at the root of fullstack

* forward env directly instead of using a guard

* just set the port in the CLI for fullstack playwright tests

* fix fullstack dioxus-cli-config feature

* fix launch server merge conflicts

* fix fullstack launch context

* run web playwright tests on 9999 to avoid port conflicts with other local servers

* fix playwright tests
2024-06-28 14:40:41 -07:00

36 lines
919 B
Rust

use clap::Parser;
/// Arguments for the serve command
#[derive(Clone, Debug, Parser, serde::Serialize, serde::Deserialize)]
pub struct ServeArguments {
/// The port the server will run on
#[clap(long)]
#[clap(default_value_t = default_port())]
pub port: u16,
/// The address the server will run on
#[clap(long)]
pub addr: Option<std::net::IpAddr>,
}
impl Default for ServeArguments {
fn default() -> Self {
Self {
port: default_port(),
addr: None,
}
}
}
impl ServeArguments {
/// Attempt to read the current serve settings from the CLI. This will only be set for the fullstack platform on recent versions of the CLI.
pub fn from_cli() -> Option<Self> {
std::env::var(crate::__private::SERVE_ENV)
.ok()
.and_then(|json| serde_json::from_str(&json).ok())
}
}
fn default_port() -> u16 {
8080
}