dioxus_aws/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use dioxus::prelude::*;

#[cfg(feature = "lambda")]
mod lambda;

#[doc = include_str!("../docs/launch.md")]
pub fn launch(app: fn() -> Element) {
    #[cfg(feature = "web")]
    dioxus::launch(app);

    #[cfg(all(not(feature = "lambda"), feature = "server"))]
    dioxus::launch(app);

    #[cfg(feature = "lambda")]
    {
        use axum::routing::*;
        use dioxus_fullstack::prelude::*;

        struct TryIntoResult(Result<ServeConfig, dioxus_fullstack::UnableToLoadIndex>);

        impl TryInto<ServeConfig> for TryIntoResult {
            type Error = dioxus_fullstack::UnableToLoadIndex;

            fn try_into(self) -> Result<ServeConfig, Self::Error> {
                self.0
            }
        }

        tokio::runtime::Runtime::new()
            .unwrap()
            .block_on(async move {
                use self::lambda::LambdaAdapter;
                let app = Router::new().serve_dioxus_application(
                    TryIntoResult(ServeConfigBuilder::default().build()),
                    app,
                );

                tracing::info!("Running in lambda mode");
                lambda_runtime::run(LambdaAdapter::from(app)).await.unwrap();
            });
    };
}