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:
Evan Almloff authored and GitHub committed 2024-06-28 14:40:41 -07:00
1 parent 9dd4427cb5
commit ffa36a67c3
18 files changed
+403 -244

No files matched your search

+55 -19
View File
@@ -156,13 +156,13 @@ impl<Cfg> LaunchBuilder<Cfg, SendContext> {
/// - Any config will be converted into `Some(config)`
/// - If the config is for another platform, it will be converted into `None`
pub trait TryIntoConfig<Config = Self> {
fn into_config(self) -> Option<Config>;
fn into_config(self, config: &mut Option<Config>);
}
// A config can always be converted into itself
impl<Cfg> TryIntoConfig<Cfg> for Cfg {
fn into_config(self) -> Option<Cfg> {
Some(self)
fn into_config(self, config: &mut Option<Cfg>) {
*config = Some(self);
}
}
@@ -176,15 +176,13 @@ impl<Cfg> TryIntoConfig<Cfg> for Cfg {
feature = "fullstack"
))]
impl TryIntoConfig<current_platform::Config> for () {
fn into_config(self) -> Option<current_platform::Config> {
None
}
fn into_config(self, config: &mut Option<current_platform::Config>) {}
}
impl<Cfg: Default + 'static, ContextFn: ?Sized> LaunchBuilder<Cfg, ContextFn> {
/// Provide a platform-specific config to the builder.
pub fn with_cfg(mut self, config: impl TryIntoConfig<Cfg>) -> Self {
self.platform_config = self.platform_config.or(config.into_config());
config.into_config(&mut self.platform_config);
self
}
@@ -234,6 +232,21 @@ mod current_platform {
#[cfg(feature = "fullstack")]
pub use dioxus_fullstack::launch::*;
#[cfg(all(feature = "fullstack", feature = "axum"))]
impl TryIntoConfig<crate::launch::current_platform::Config>
for ::dioxus_fullstack::prelude::ServeConfigBuilder
{
fn into_config(self, config: &mut Option<crate::launch::current_platform::Config>) {
match config {
Some(config) => config.set_server_cfg(self),
None => {
*config =
Some(crate::launch::current_platform::Config::new().with_server_cfg(self))
}
}
}
}
#[cfg(any(feature = "desktop", feature = "mobile"))]
if_else_cfg! {
if not(feature = "fullstack") {
@@ -242,9 +255,25 @@ mod current_platform {
#[cfg(not(feature = "desktop"))]
pub use dioxus_mobile::launch::*;
} else {
impl TryIntoConfig<crate::launch::current_platform::Config> for ::dioxus_desktop::Config {
fn into_config(self) -> Option<crate::launch::current_platform::Config> {
None
if_else_cfg! {
if feature = "desktop" {
impl TryIntoConfig<crate::launch::current_platform::Config> for ::dioxus_desktop::Config {
fn into_config(self, config: &mut Option<crate::launch::current_platform::Config>) {
match config {
Some(config) => config.set_desktop_config(self),
None => *config = Some(crate::launch::current_platform::Config::new().with_desktop_config(self)),
}
}
}
} else {
impl TryIntoConfig<crate::launch::current_platform::Config> for ::dioxus_mobile::Config {
fn into_config(self, config: &mut Option<crate::launch::current_platform::Config>) {
match config {
Some(config) => config.set_mobile_cfg(self),
None => *config = Some(crate::launch::current_platform::Config::new().with_mobile_cfg(self)),
}
}
}
}
}
}
@@ -256,9 +285,7 @@ mod current_platform {
pub use dioxus_static_site_generation::launch::*;
} else {
impl TryIntoConfig<crate::launch::current_platform::Config> for ::dioxus_static_site_generation::Config {
fn into_config(self) -> Option<crate::launch::current_platform::Config> {
None
}
fn into_config(self, config: &mut Option<crate::launch::current_platform::Config>) {}
}
}
}
@@ -268,9 +295,20 @@ mod current_platform {
if not(any(feature = "desktop", feature = "mobile", feature = "fullstack", feature = "static-generation")) {
pub use dioxus_web::launch::*;
} else {
impl TryIntoConfig<crate::launch::current_platform::Config> for ::dioxus_web::Config {
fn into_config(self) -> Option<crate::launch::current_platform::Config> {
None
if_else_cfg! {
if feature = "fullstack" {
impl TryIntoConfig<crate::launch::current_platform::Config> for ::dioxus_web::Config {
fn into_config(self, config: &mut Option<crate::launch::current_platform::Config>) {
match config {
Some(config) => config.set_web_config(self),
None => *config = Some(crate::launch::current_platform::Config::new().with_web_config(self)),
}
}
}
} else {
impl TryIntoConfig<crate::launch::current_platform::Config> for ::dioxus_web::Config {
fn into_config(self, config: &mut Option<crate::launch::current_platform::Config>) {}
}
}
}
}
@@ -290,9 +328,7 @@ mod current_platform {
pub use dioxus_liveview::launch::*;
} else {
impl<R: ::dioxus_liveview::LiveviewRouter> TryIntoConfig<crate::launch::current_platform::Config> for ::dioxus_liveview::Config<R> {
fn into_config(self) -> Option<crate::launch::current_platform::Config> {
None
}
fn into_config(self, config: &mut Option<crate::launch::current_platform::Config>) {}
}
}
}