pub struct ServeConfigBuilder { /* private fields */ }
server
only.Expand description
A ServeConfig is used to configure how to serve a Dioxus application. It contains information about how to serve static assets, and what content to render with [dioxus-ssr
].
Implementations§
Source§impl ServeConfigBuilder
impl ServeConfigBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new ServeConfigBuilder with incremental static generation disabled and the default index.html settings
Sourcepub fn incremental(self, cfg: IncrementalRendererConfig) -> Self
pub fn incremental(self, cfg: IncrementalRendererConfig) -> Self
Enable incremental static generation. Incremental static generation caches the rendered html in memory and/or the file system. It can be used to improve performance of heavy routes.
use dioxus::prelude::*;
// Finally, launch the app with the config
LaunchBuilder::new()
// Only set the server config if the server feature is enabled
.with_cfg(server_only!(ServeConfigBuilder::default().incremental(IncrementalRendererConfig::default())))
.launch(app);
Sourcepub fn index_html(self, index_html: String) -> Self
pub fn index_html(self, index_html: String) -> Self
Set the contents of the index.html file to be served. (precedence over index_path)
Sourcepub fn index_path(self, index_path: PathBuf) -> Self
pub fn index_path(self, index_path: PathBuf) -> Self
Set the path of the index.html file to be served. (defaults to {assets_path}/index.html)
Sourcepub fn root_id(self, root_id: &'static str) -> Self
pub fn root_id(self, root_id: &'static str) -> Self
Set the id of the root element in the index.html file to place the prerendered content into. (defaults to main)
§Example
If your index.html file looks like this:
<!DOCTYPE html>
<html>
<head>
<title>My App</title>
</head>
<body>
<div id="my-custom-root"></div>
</body>
</html>
You can set the root id to "my-custom-root"
to render the app into that element:
use dioxus::prelude::*;
// Finally, launch the app with the config
LaunchBuilder::new()
// Only set the server config if the server feature is enabled
.with_cfg(server_only! {
ServeConfigBuilder::default().root_id("app")
})
// You also need to set the root id in your web config
.with_cfg(web! {
dioxus::web::Config::default().rootname("app")
})
// And desktop config
.with_cfg(desktop! {
dioxus::desktop::Config::default().with_root_name("app")
})
.launch(app);
Sourcepub fn context_providers(
self,
state: Arc<Vec<Box<dyn Fn() -> Box<dyn Any> + Send + Sync + 'static>>>,
) -> Self
pub fn context_providers( self, state: Arc<Vec<Box<dyn Fn() -> Box<dyn Any> + Send + Sync + 'static>>>, ) -> Self
Provide context to the root and server functions. You can use this context
while rendering with consume_context
or in server functions with FromContext
.
Context will be forwarded from the LaunchBuilder if it is provided.
use dioxus::prelude::*;
dioxus::LaunchBuilder::new()
// You can provide context to your whole app (including server functions) with the `with_context` method on the launch builder
.with_context(server_only! {
1234567890u32
})
.launch(app);
#[server]
async fn read_context() -> Result<u32, ServerFnError> {
// You can extract values from the server context with the `extract` function
let FromContext(value) = extract().await?;
Ok(value)
}
fn app() -> Element {
let future = use_resource(read_context);
rsx! {
h1 { "{future:?}" }
}
}
Sourcepub fn streaming_mode(self, mode: StreamingMode) -> Self
pub fn streaming_mode(self, mode: StreamingMode) -> Self
Set the streaming mode for the server. By default, streaming is disabled.
dioxus::LaunchBuilder::new()
.with_context(server_only! {
dioxus::fullstack::ServeConfig::builder().streaming_mode(dioxus::fullstack::StreamingMode::OutOfOrder)
})
.launch(app);
Sourcepub fn enable_out_of_order_streaming(self) -> Self
pub fn enable_out_of_order_streaming(self) -> Self
Enable out of order streaming. This will cause server futures to be resolved out of order and streamed to the client as they resolve.
It is equivalent to calling streaming_mode(StreamingMode::OutOfOrder)
dioxus::LaunchBuilder::new()
.with_context(server_only! {
dioxus::fullstack::ServeConfig::builder().enable_out_of_order_streaming()
})
.launch(app);
Sourcepub fn build(self) -> Result<ServeConfig, UnableToLoadIndex>
pub fn build(self) -> Result<ServeConfig, UnableToLoadIndex>
Build the ServeConfig. This may fail if the index.html file is not found.
Trait Implementations§
Source§impl Clone for ServeConfigBuilder
impl Clone for ServeConfigBuilder
Source§fn clone(&self) -> ServeConfigBuilder
fn clone(&self) -> ServeConfigBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more