diff --git a/.github/workflows/build-worker.yml b/.github/workflows/build-worker.yml index 9e440ec..a4ad20f 100644 --- a/.github/workflows/build-worker.yml +++ b/.github/workflows/build-worker.yml @@ -16,7 +16,7 @@ jobs: node-version-file: '.nvmrc' - name: Install Wrangler - run: npm install -g wrangler@3.32.0 + run: npm install -g wrangler@3.34.2 - name: Install Rust uses: actions-rs/toolchain@v1 diff --git a/adapter/Cargo.toml b/adapter/Cargo.toml index 834fa98..294a93a 100644 --- a/adapter/Cargo.toml +++ b/adapter/Cargo.toml @@ -16,7 +16,7 @@ crate-type = ["cdylib", "lib"] [dependencies] axum = { version = "^0.7.1", default-features = false } -worker = { version = "^0.0.20" } +worker = { version = "^0.0.21" } axum-wasm-macros = "^0.1.0" futures = "0.3.29" diff --git a/adapter/README.md b/adapter/README.md index 8a68b68..ed0071e 100644 --- a/adapter/README.md +++ b/adapter/README.md @@ -4,6 +4,24 @@ An adapter to easily run an [Axum](https://github.com/tokio-rs/axum) server in a Cloudflare worker. +## Cloudflare workers perliminary native support for Axum on 0.0.21+ + +Axum support in workers-rs is enabled by the [http](https://github.com/cloudflare/workers-rs?tab=readme-ov-file#http-feature) feature in worker-rs. + +This is possible because both Axum and worker-rs http uses the same [http](https://docs.rs/http/latest/http/) crate. + +This adapter can be used as an easy way to migrate from the non http workers-rs version to the http version: +1. Do not change your current workers-rs project dependency on the non http version of workers-rs (keep the http flag disabled). +1. Add the dependency to this adapter. +2. Add a catch all route to the existing router: +```rust + .or_else_any_method_async("/*catchall", |_, ctx| async move { +``` +3. Inside the catch all route, add an axum router like in the example bellow. +4. Start to incrementally migrate the paths one by one, from the old router to the axum router. +5. Once finished, drop the dependency on this adapter and enable the "http" flag on workers-rs. +6. If you have any issues you can ask for help on #rust-on-workers on discord or open an issue in workers-rs github. + ## Usage ```rust diff --git a/example/Cargo.toml b/example/Cargo.toml index 840e8f8..709259c 100644 --- a/example/Cargo.toml +++ b/example/Cargo.toml @@ -19,7 +19,7 @@ serde_json = "1.0.108" tower-service = "0.3.2" url = "2.3.1" wasm-bindgen-futures = "0.4.34" -worker = "0.0.20" +worker = "^0.0.21" # The `console_error_panic_hook` crate provides better debugging of panics by # logging them with `console.error`. This is great for development, but requires diff --git a/example/wrangler.toml b/example/wrangler.toml index 374ac2a..a0c3a3a 100644 --- a/example/wrangler.toml +++ b/example/wrangler.toml @@ -5,7 +5,7 @@ main = "build/worker/shim.mjs" name = "axum-cloudflare-adapter" [vars] -WORKERS_RS_VERSION = "0.0.18" +WORKERS_RS_VERSION = "0.0.21" [build] command = "cargo install -q worker-build && worker-build --release"