This project showcases how to use MoonBit to develop a cloudflare worker.
This project contains four packages:
js: Core JavaScript binding. Binds things that is defined in the ECMAScript.web: API that are part of the WinterCG. In other words, standard APIs.cloudflare: Cloudflare APIs.lib: Actual server definition. Inspired by http4s though naively defined.
The bindings are expected to be generated from an IDL in the future.
The FFIs are divided to three layers:
*_ffi: All parameters and results areJS_Value, which stands for any value in JavaScript.*_js: All parameters and results are specific JS types, except forPromise[T](Warning: Do not try to createPromise[Promise[T]]).*:ArrayandStringare converted to MoonBit type for ergonomics.
All you need is moon node and pnpm.
You can simply run pnpm install and then pnpm dev. The wrangler will spin
up a server, and you can access it with the commands provided.
You may use curl or other means to visit all the APIs. The expected behavior
is specified in the test/index.spec.ts. Simply run pnpm test and check that
it still works.