A wrangler template for a Cloudflare Workers project with Asterius, a Haskell to WebAssembly compiler.
src/worker.mjsis the 'entry' module that defines thefetchevent listener and loads the Asterius runtime.src/worker.hsimplements the actual request handling code in Haskell.webpack.config.jsholds the webpack config that integrates the Asterius build process nicely with Wrangler.
As Asterius is in the alpha development stage, this template may become outdated at any time.
- Node.js (tested with 13.x)
- Docker for running the Asterius compiler provided as a Docker image
-
Generate a project with wrangler if you have it installed in your system:
wrangler generate myworker https://github.com/ento/worker-haskell-templateIf not, either clone this repo or download its archive from GitHub and unarchive locally.
-
Install dependencies:
cd myworker npm install -
Edit
wrangler.tomland replace theaccount_idvalue with your Cloudflare account ID.If you didn't use wrangler to generate the project, replace the
namevalue as well.For more information, including how to deploy to your Cloudflare Zone, see Cloudflare's documentation.
-
Build and test:
npm run build npm run test -
Preview with:
npx wrangler previewYou should see "Hello from Haskell" in response to
GETrequests. Send aPOSTrequest with a body like{"name": "world"}to get "Hello world" in return. -
Publish:
npx wrangler publish
This template is licensed under the terms of the 0BSD license.