create a serveconfig builder
This commit is contained in:
1 parent
1d395d572f
commit
1be48c4aa8
4 files changed
+74
-39
No files matched your search
+21
-12
@@ -2,38 +2,47 @@
|
||||
use dioxus_core::prelude::*;
|
||||
|
||||
mod adapters;
|
||||
mod serve;
|
||||
mod server_fn;
|
||||
|
||||
pub mod prelude {
|
||||
#[cfg(feature = "axum")]
|
||||
pub use crate::adapters::axum_adapter::*;
|
||||
pub use crate::serve::ServeConfig;
|
||||
pub use crate::server_fn::{DioxusServerContext, ServerFn};
|
||||
pub use server_fn::{self, ServerFn as _, ServerFnError};
|
||||
pub use server_macro::*;
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
fn dioxus_ssr_html(
|
||||
title: &str,
|
||||
application_name: &str,
|
||||
base_path: Option<&str>,
|
||||
head: Option<&str>,
|
||||
app: Component,
|
||||
) -> String {
|
||||
fn dioxus_ssr_html(cfg: serve::ServeConfig) -> String {
|
||||
use prelude::ServeConfig;
|
||||
|
||||
let ServeConfig {
|
||||
app,
|
||||
application_name,
|
||||
base_path,
|
||||
head,
|
||||
..
|
||||
} = cfg;
|
||||
|
||||
let application_name = application_name.unwrap_or("dioxus");
|
||||
|
||||
let mut vdom = VirtualDom::new(app);
|
||||
let _ = vdom.rebuild();
|
||||
let renderered = dioxus_ssr::pre_render(&vdom);
|
||||
let base_path = base_path.unwrap_or(".");
|
||||
let head = head.unwrap_or_default();
|
||||
let head = head.unwrap_or(
|
||||
r#"<title>Dioxus Application</title>
|
||||
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta charset="UTF-8" />"#,
|
||||
);
|
||||
format!(
|
||||
r#"
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>{title}</title>
|
||||
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta charset="UTF-8" />
|
||||
{head}
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Reference in new issue
Block a user