Expand description
§dioxus-cloudflare
The missing bridge between Dioxus server functions and Cloudflare Workers.
This crate connects Dioxus’s #[server] macro (via the axum_core feature
in dioxus-fullstack) to the Cloudflare Workers runtime. Write one function
in your shared crate — it compiles to a client fetch stub and a Worker
handler automatically.
§Quick Start
Worker entry point:
ⓘ
use worker::*;
use dioxus_cloudflare::prelude::*;
extern "C" { fn __wasm_call_ctors(); }
#[event(fetch)]
async fn fetch(req: Request, env: Env, _ctx: Context) -> Result<Response> {
unsafe { __wasm_call_ctors(); }
dioxus_cloudflare::handle(req, env).await
}Server function (shared crate):
ⓘ
use dioxus::prelude::*;
use dioxus_cloudflare::prelude::*;
#[server]
pub async fn get_user(id: String) -> Result<User, ServerFnError> {
let db = cf::d1("DB")?;
// ...
}Client component (calls it like a normal function):
ⓘ
let user = get_user("abc".into()).await;§Architecture
Client WASM Cloudflare Worker
┌──────────┐ fetch() ┌─────────────────────┐
│ #[server] │ ───────────▶ │ handle(req, env) │
│ generates │ │ ↓ set_context() │
│ POST to │ │ ↓ worker→http req │
│ /api/... │ │ ↓ Axum dispatch │
│ │ ◀─ stream ─ │ ↓ http→worker resp │
└──────────┘ └─────────────────────┘Modules§
- cf
- Access Cloudflare Worker bindings and request context from inside
#[server]functions. - prelude
- Convenience re-exports for common usage.
Structs§
- CfError
- Newtype wrapper around
worker::Errorthat implements conversion toServerFnError. - Handler
- Configurable request handler with before/after middleware hooks.
- Session
Config - Session backend configuration.
Traits§
- CfResult
Ext - Extension trait for
worker::Result<T>that converts errors into a type compatible withServerFnErrorvia the?operator.
Functions§
- handle
- Handle an incoming Cloudflare Worker request by dispatching it through the Dioxus server function router.