Skip to content

Latest commit

 

History

History
98 lines (64 loc) · 2.43 KB

README.md

File metadata and controls

98 lines (64 loc) · 2.43 KB

Use a-skua/cf_workers.dart lib for Cloudflare Workers to send HTTP(s) requests from inside WASM

Instructions for this devcontainer

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 in GitHub Codespaces

Preparation

  1. Open this repo in devcontainer, e.g. using Github Codespaces. Type or copy/paste following commands to devcontainer's terminal.

Installation

  1. cd into the folder of this example:
cd cloudflare-workers
  1. Install the Cloudflare's Wrangler tool:
yarn add --dev wrangler
  1. Clone the repo of a-skua/cf_workers.dart:
git clone --depth=1 https://github.com/a-skua/cf_workers.dart
  1. cd into the folder of cloned repo:
cd cf_workers.dart
  1. Ensure all dependencies are installed:
dart pub get

Building

  1. cd into the example subfolder, where sources of example are located:
cd example
  1. 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
  1. Compile the example:
dart compile wasm example.dart -o __dart/example.wasm

Test locally with Wrangler

  1. 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.

  1. You can see the result in browser, as this sample Worker acts as a dummy webproxy.

Deploy to Cloudflare

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

Finish

Perform your own experiments if desired.