A batteries included template for kick starting a TypeScript Cloudflare worker project that connects to a hosted RavenDB database.
RavenDB is a NoSQL document database for distributed applications offering industry-leading security without compromising performance. With a RavenDB database you can set up a NoSQL data architecture or add a NoSQL layer to your current relational database.
The easiest way to get started with RavenDB is by creating a free RavenDB Cloud account or requesting a free license to download it yourself.
If you are brand new to RavenDB, we recommend starting with the Getting Started guide, the RavenDB bootcamp, or the Try RavenDB experience.
To create a my-project
directory using this template, run:
$ npm init cloudflare my-project https://github.com/ravendb/template-cloudflare-worker
# or
$ yarn create cloudflare my-project https://github.com/ravendb/template-cloudflare-worker
# or
$ pnpm create cloudflare my-project https://github.com/ravendb/template-cloudflare-worker
Note: Each command invokes
create-cloudflare
for project creation.
To start the worker:
$ npm start
Read through the step-by-step guide in the RavenDB docs that covers how to get up and running successfully with this template by configuring the worker to use mTLS certificates.
In wrangler.toml
:
DB_URLS
: Comma-separated values for your RavenDB cluster node URLsDB_NAME
: Database to connect to. Warning: Ensure the database exists otherwise you will receive aDatabaseNotFoundException
.
These will automatically be set during deployment and will override any settings in the Cloudflare dashboard.
You can manually deploy through the Wrangler CLI using wrangler deploy
but the template is automatically configured for CI/CD using GitHub Actions workflows. You will need the following secrets:
CF_API_TOKEN
-- The API token secret for your deployment. Requires access to workers.CF_ACCOUNT_ID
-- Your global Cloudflare account ID
These are set automatically if using the Cloudflare Worker Deployment wizard.
Obtain your RavenDB client certificate from the Cloud dashboard, Manage Server > Certificates in the Studio, or the Raven Admin CLI. You will need the .crt
(public key) and .key
(private key) files.
Upload the mTLS certificate using wrangler
:
$ npx wrangler mtls-certificate upload --cert cert.crt --key key.key --name cert_name
This will output your <CERTIFICATE_ID>
to use in your wrangler.toml
file for the DB_CERT
binding. See the Cloudflare mTLS for Workers documentation for more.