Awesome
worker-haskell-template
A wrangler
template for a Cloudflare Workers project with Asterius, a Haskell to WebAssembly compiler.
src/worker.mjs
is the 'entry' module that defines thefetch
event listener and loads the Asterius runtime.src/worker.hs
implements the actual request handling code in Haskell.webpack.config.js
holds 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.
Prerequisites
- Node.js (tested with 13.x)
- Docker for running the Asterius compiler provided as a Docker image
Usage
-
Generate a project with wrangler if you have it installed in your system:
wrangler generate myworker https://github.com/ento/worker-haskell-template
If not, either clone this repo or download its archive from GitHub and unarchive locally.
-
Install dependencies:
cd myworker npm install
-
Edit
wrangler.toml
and replace theaccount_id
value with your Cloudflare account ID.If you didn't use wrangler to generate the project, replace the
name
value 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 preview
You should see "Hello from Haskell" in response to
GET
requests. Send aPOST
request 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.