axum-cloudflare-adapter

Crates.io

An adapter to easily allow an Axum server to be run within a Cloudflare worker.

Usage

```rust use worker::*;

use axum::{ response::{Html}, routing::get, Router as AxumRouter, }; use axumcloudflareadapter::{toaxumrequest, toworkerresponse}; use tower_service::Service;

async fn index() -> Html<&'static str> { Html("

Hello from Axum!

") }

[event(fetch)]

pub async fn main(req: Request, _env: Env, _ctx: worker::Context) -> Result { let mut _router: AxumRouter = AxumRouter::new() .route("/", get(index));

let axum_request = to_axum_request(req).await.unwrap();
let axum_response = _router.call(axum_request).await.unwrap();
let response = to_worker_response(axum_response).await.unwrap();

Ok(response)

} ```

Running tests

wasm-pack test --firefox --headless

Building

cargo build --target wasm32-unknown-unknown

Example

The /example directory contains a Cloudflare worker running an Axum sever