Struct ServeConfigBuilder

Source
pub struct ServeConfigBuilder { /* private fields */ }
Available on crate feature 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

Source

pub fn new() -> Self

Create a new ServeConfigBuilder with incremental static generation disabled and the default index.html settings

Source

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);
Source

pub fn index_html(self, index_html: String) -> Self

Set the contents of the index.html file to be served. (precedence over index_path)

Source

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)

Source

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);
Source

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:?}" }
    }
}
Source

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);
Source

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);
Source

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

Source§

fn clone(&self) -> ServeConfigBuilder

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for ServeConfigBuilder

Source§

fn default() -> ServeConfigBuilder

Returns the “default value” for a type. Read more
Source§

impl TryInto<ServeConfig> for ServeConfigBuilder

Source§

type Error = UnableToLoadIndex

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<ServeConfig, Self::Error>

Performs the conversion.
Source§

impl LaunchConfig for ServeConfigBuilder

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> MaybeSendSync for T