Tested with Dart SDK v3.5.2, a-skua/cf_workers.dart v1.0.0-rc.2, Wrangler v4.4.1.
Note
Please make sure you started your codespace using alternate devcontainer, cf-workers
, since Wrangler
requires
glib 2.35+ .
- Open this repo in devcontainer, e.g. using Github Codespaces. Type or copy/paste following commands to devcontainer's terminal.
cd
into the folder of this example:
cd cloudflare-workers
- Install the Cloudflare's Wrangler tool:
yarn add --dev wrangler
- Clone the repo of a-skua/cf_workers.dart:
git clone --depth=1 https://github.com/a-skua/cf_workers.dart
cd
into the folder of cloned repo:
cd cf_workers.dart
- Ensure all dependencies are installed:
dart pub get
cd
into theexample
subfolder, where sources of example are located:
cd example
- Optionally change the URL to fetch (default value, example.com, works OK too):
sed -i.bak 's|https://example.com|https://httpbin.org/anything|' example.dart
- Compile the example:
dart compile wasm example.dart -o __dart/example.wasm
- Run
wrangler dev
to temporarily publish project to Web:
npx wrangler dev
Codespace will show you "Open in Browser" button. Just click that button or obtain web address from "Forwarded Ports" tab.
- You can see the result in browser, as this sample Worker acts as a dummy webproxy.
If you want to publish this Worker onto Cloudflare, run the deploy command (make sure you have Wrangler configured
with wrangler login
, etc):
npx wrangler deploy
Perform your own experiments if desired.