|
use dioxus::prelude::*; |
|
|
|
// The entry point for the production server (with TLS support) |
|
#[cfg(all(feature = "server", not(debug_assertions)))] |
|
#[tokio::main] |
|
async fn main() { |
|
use axum::ServiceExt; |
|
use axum::{routing::get, Router}; |
|
use axum_server::tls_openssl::OpenSSLConfig; |
|
use std::env; |
|
use std::net::SocketAddr; |
|
// Get the address the server should run on. If the CLI is running, the CLI proxies fullstack into the main address |
|
// and we use the generated address the CLI gives us |
|
let address = dioxus::cli_config::fullstack_address_or_localhost(); |
|
|
|
// Set up the axum router |
|
let router = axum::Router::new() |
|
// You can add a dioxus application to the router with the `serve_dioxus_application` method |
|
// This will add a fallback route to the router that will serve your component and server functions |
|
.serve_dioxus_application(ServeConfigBuilder::default(), App); |
|
|
|
let certs_path = env::var("APP_CERT_DIR").unwrap_or_else(|_| "./certs".into()); |
|
let config = OpenSSLConfig::from_pem_file( |
|
format!("{}/cert.pem", certs_path).as_str(), |
|
format!("{}/key.pem", certs_path).as_str(), |
|
).expect("Server require valid certificate to run"); |
|
|
|
|
|
// Finally, we can launch the server |
|
let app = router.into_service(); |
|
// let listener = tokio::net::TcpListener::bind(address).await.unwrap(); |
|
// axum::serve(listener, router).await.unwrap(); |
|
|
|
println!("Serving route for:{address}"); |
|
axum_server::bind_openssl(address, config) |
|
.serve(app.into_make_service()) |
|
.await |
|
.unwrap(); |
|
} |
|
|
|
// For any other platform, we just launch the app |
|
#[cfg(any(feature= "web", debug_assertions))] //to deliver |
|
fn main() { |
|
dioxus::launch(App); |
|
} |
|
#[component] |
|
pub fn App() -> Element { |
|
rsx! {"hello world"} |
|
} |
|
|