Skip to content

Commit

Permalink
Updated to the latest worker-rs and latest wrangler (#26)
Browse files Browse the repository at this point in the history
* Updated to the latest workers-rs 0.0.21.

* Updated to the latest wrangler.

* Update README.md with Cloudflare http status update and migration information.

* Update README.md

Tried to get the suggestions in.
  • Loading branch information
spigaz authored Mar 19, 2024
1 parent 443b030 commit 1ca2890
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion adapter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
18 changes: 18 additions & 0 deletions adapter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 1ca2890

Please sign in to comment.