Initial commit.
This commit is contained in:
commit
9a6709e02c
8 changed files with 227 additions and 0 deletions
53
src/main.rs
Normal file
53
src/main.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
#[cfg(feature = "server")]
|
||||
use axum::Extension;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
const FAVICON: Asset = asset!("/assets/favicon.ico");
|
||||
const MAIN_CSS: Asset = asset!("/assets/main.css");
|
||||
const HEADER_SVG: Asset = asset!("/assets/header.svg");
|
||||
|
||||
#[cfg(not(feature = "server"))]
|
||||
fn main() {
|
||||
dioxus::launch(App);
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, serde::Deserialize, serde::Serialize)]
|
||||
struct TestType(String);
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
fn main() {
|
||||
tokio::runtime::Runtime::new()
|
||||
.unwrap()
|
||||
.block_on(async move {
|
||||
// Connect to dioxus' logging infrastructure
|
||||
dioxus::logger::initialize_default();
|
||||
// Connect to the IP and PORT env vars passed by the Dioxus CLI (or your dockerfile)
|
||||
let socket_addr = dioxus::cli_config::fullstack_address_or_localhost();
|
||||
// Build a custom axum router
|
||||
let router = axum::Router::new()
|
||||
.layer(Extension(TestType::default()))
|
||||
.serve_dioxus_application(ServeConfigBuilder::new(), App)
|
||||
.into_make_service();
|
||||
// And launch it!
|
||||
let listener = tokio::net::TcpListener::bind(socket_addr).await.unwrap();
|
||||
axum::serve(listener, router).await.unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn App() -> Element {
|
||||
rsx! {
|
||||
button {
|
||||
onclick: move |_| async move {
|
||||
test().await;
|
||||
},
|
||||
"Test"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[server]
|
||||
async fn test() -> Result<(), ServerFnError> {
|
||||
let test: Extension<TestType> = extract().await?;
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue