Open Source
Deployment
Learn how to deploy Rates API to Cloudflare Workers for production use.
Rates API deploys two Cloudflare Workers:
| Worker | Serves |
|---|---|
ratesapi-nz | API routes such as /api/v1/* and /openapi |
ratesapi-nz-docs | The Fumadocs site and docs-only routes |
Cloudflare D1 stores latest datasets and historical snapshots for the API Worker.
Prerequisites
- A Cloudflare account
- The project set up for local development
- Bun installed
- Wrangler CLI for Cloudflare Workers and D1 management
Cloudflare D1
Create the D1 database and apply the schema before deploying the API Worker.
wrangler login
wrangler d1 execute ratesapi-data --file=./apps/api/schema.sql
Worker Configuration
The API Worker is configured in apps/api/wrangler.toml. It owns the public API path routes on the apex domain:
[[routes]]
pattern = "ratesapi.nz/api/v1/*"
zone_name = "ratesapi.nz"
[[routes]]
pattern = "ratesapi.nz/openapi"
zone_name = "ratesapi.nz"
The docs Worker is configured in apps/docs/wrangler.toml. It owns the apex Custom Domain:
[[routes]]
pattern = "ratesapi.nz"
custom_domain = true
This lets the docs app serve https://ratesapi.nz/, while the API Worker still handles https://ratesapi.nz/api/v1/* and OpenAPI routes.
Dry-Run Deployment
Run the same deployability checks used by CI:
bun run deploy:dry-run
bun run build:docs
bun run deploy:docs:dry-run
Deploy
Deploy the API Worker:
bun run deploy
Build and deploy the docs Worker:
bun run build:docs
bun run deploy:docs
Post-Deployment Setup
- Confirm
https://ratesapi.nz/serves the docs app. - Confirm
https://ratesapi.nz/api/v1/healthserves the API Worker. - Confirm
https://ratesapi.nz/openapiloads the Scalar API client. - Confirm
https://ratesapi.nz/openapi/jsonreturns the generated OpenAPI document. - Confirm the hourly scraping workflow has the
CLOUDFLARE_API_TOKEN,CLOUDFLARE_ACCOUNT_ID, and D1 database environment it needs.
Production Considerations
- Keep route ownership clear: docs Worker owns the apex Custom Domain, API Worker owns API path routes.
- Review the deploy dry-run job when Worker bindings or route patterns change.
- Keep endpoint docs and OpenAPI schemas aligned with route changes.
- Monitor scraper failures separately from Worker uptime.