mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-17 14:18:27 +00:00
fix axum adapter
This commit is contained in:
parent
83d513ef36
commit
0b80d32d18
1 changed files with 16 additions and 7 deletions
|
@ -18,7 +18,10 @@ use crate::{
|
|||
|
||||
pub trait DioxusRouterExt {
|
||||
fn register_server_fns(self, server_fn_route: &'static str) -> Self;
|
||||
fn serve_dioxus_application(self, cfg: ServeConfig) -> Self;
|
||||
fn serve_dioxus_application<P: Clone + Send + Sync + 'static>(
|
||||
self,
|
||||
cfg: ServeConfig<P>,
|
||||
) -> Self;
|
||||
}
|
||||
|
||||
impl DioxusRouterExt for Router {
|
||||
|
@ -37,18 +40,24 @@ impl DioxusRouterExt for Router {
|
|||
router
|
||||
}
|
||||
|
||||
fn serve_dioxus_application(self, cfg: ServeConfig) -> Self {
|
||||
fn serve_dioxus_application<P: Clone + Send + Sync + 'static>(
|
||||
self,
|
||||
cfg: ServeConfig<P>,
|
||||
) -> Self {
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
// Serve the dist folder and the index.html file
|
||||
let serve_dir = ServeDir::new("dist");
|
||||
|
||||
self.register_server_fns(cfg.server_fn_route.unwrap_or_default())
|
||||
.route("/", get(move || {
|
||||
let rendered = dioxus_ssr_html(cfg);
|
||||
async move { Full::from(rendered) }
|
||||
}))
|
||||
.fallback_service( serve_dir)
|
||||
.route(
|
||||
"/",
|
||||
get(move || {
|
||||
let rendered = dioxus_ssr_html(&cfg);
|
||||
async move { Full::from(rendered) }
|
||||
}),
|
||||
)
|
||||
.fallback_service(serve_dir)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue