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
This commit is contained in:
1 parent
9dd4427cb5
commit
ffa36a67c3
18 files changed
+403
-244
No files matched your search
@@ -8,6 +8,10 @@ mod bundle;
|
||||
pub use bundle::*;
|
||||
mod cargo;
|
||||
pub use cargo::*;
|
||||
#[cfg(feature = "cli")]
|
||||
mod serve;
|
||||
#[cfg(feature = "cli")]
|
||||
pub use serve::*;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod __private {
|
||||
@@ -28,6 +32,11 @@ pub mod __private {
|
||||
std::env::remove_var(CONFIG_ENV);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "cli")]
|
||||
/// The environment variable that stores the CLIs serve configuration.
|
||||
/// We use this to communicate between the CLI and the server for fullstack applications.
|
||||
pub const SERVE_ENV: &str = "DIOXUS_SERVE_CONFIG";
|
||||
}
|
||||
|
||||
/// An error that occurs when the dioxus CLI was not used to build the application.
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user