Starting template for serverless http service in WASM using Cloudflare Workers.
- Fully async
- Request/response bodies can be text, json(serialized), or binary
- Non-blocking structured logging
- Deferred tasks that run after response is returned to client
To get started, use
wrangler generate -t rust PROJECT \
https://github.com/stevelr/rustwasm-service-template
where PROJECT is your project name.
- You'll need a Cloudflare account that is enabled for Workers. This is easiest to set up if you also get a domain on Cloudflare; they will set up the DNS for you and automatically acquire HTTPS certs.
- Pick a host name for your service. If your domain is "example.com" and
your service will be at "api.example.com", add
route = "api.example.com/*"
towrangler.toml
, and addapi
as an AAAA entry with an IP address of "100::" in the DNS settings page on the Cloudflare account. - Important: Set SSL/TLS encryption mode to Full (or Strict) in your Cloudflare domain settings.
- Update
wrangler.toml
to setaccount_id
,zone_id
, androute
- The worker is set by default to require TLSv1.3, which is considered more secure than previous versions. If you want to accept TLSv1.2 additionally, change the condition expression in worker/worker.js
-
The basic logger uses the equivalent of javascript's console.log. When using
wrangler dev
orwrangler preview
, those logs are easy to see on the console. For "production" services, check on Cloudflare's log panel. -
if you have a Coralogix account, update
config.toml
to setlogger="coralogix"
, and setapi_key
. -
For structured logging with Coralogix, you can get started with a free-tier account. Logs can be viewed in real time, either in a browser, on the Coralogix dashboard, or using the livetail cli tool.
livetail --api-key XXXXX --region eu --format pretty