Improve documentation for the fullstack crate (#2952)
* improve documentation for the fullstack server context * Add a section about axum integration to the crate root docs * make serve_dioxus_application accept the cfg builder directly * remove unused server_fn module * improve fullstack config docs * improve documentation for the server function macro * fix axum router extension link * Fix doc tests * Fix launch builder * Remove redundant server_only inside server function * Fix isrg config path
This commit is contained in:
1 parent
cda8bb24f1
commit
6a0c1c392b
12 files changed
+625
-218
No files matched your search
@@ -0,0 +1,40 @@
|
||||
This method interacts with information from the current request. The request may come from:
|
||||
|
||||
1. The initial SSR render if this method called from a [`Component`](dioxus_lib::prelude::component) or a [`server`](crate::prelude::server) function that is called during the initial render
|
||||
|
||||
```rust
|
||||
#[component]
|
||||
fn PrintHtmlRequestInfo() -> Element {
|
||||
// The server context only exists on the server, so we need to put it behind a server_only! config
|
||||
server_only! {
|
||||
// Since we are calling this from a component, the server context that is returned will be from
|
||||
// the html request for ssr rendering
|
||||
println!("headers are {:?}", server_context().request_parts().headers);
|
||||
}
|
||||
rsx! {}
|
||||
}
|
||||
```
|
||||
|
||||
2. A request to a [`server`](crate::prelude::server) function called directly from the client (either on desktop/mobile or on the web frontend after the initial render)
|
||||
|
||||
```rust
|
||||
#[server]
|
||||
async fn read_headers() -> Result<(), ServerFnError> {
|
||||
// Since we are calling this from a server function, the server context that is may be from the
|
||||
// initial request or a request from the client
|
||||
println!("headers are {:?}", server_context().request_parts().headers);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn CallServerFunction() -> Element {
|
||||
rsx! {
|
||||
button {
|
||||
// If you click the button, the server function will be called and the server context will be
|
||||
// from the client request
|
||||
onclick: move |_| read_headers().await,
|
||||
"Call server function"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in new issue
Block a user