Cloudflare Worker integration
The Fauna integration for Cloudflare lets you connect and query a Fauna database from a Cloudflare Worker.
When set up, the integration automatically creates a Fauna authentication key. The integration stores the key’s secret in a Worker environment variable. You can use the environment variable with the Fauna JavaScript driver to run queries from the Worker.
Set up the integration
To connect a Cloudflare worker to an existing Fauna database:
-
Log in to the Cloudflare dashboard and select your account.
-
In Account Home, select Workers & Pages.
-
In Overview, select your Worker.
-
Select Integrations > Fauna.
-
Follow the setup flow and select your Fauna database.
-
In your Cloudflare Worker, install the Fauna JavaScript driver:
npm install fauna
The following example shows how to run a Fauna query in a Cloudflare Worker. The credentials needed to connect to Fauna have been automatically added as secrets to your Worker through the integration:
import { Client, fql } from 'fauna'; export default { async fetch(request, env) { const fauna = new Client({ secret: env.FAUNA_SECRET }); const query = fql`Product.all()`; const result = await fauna.query(query); return Response.json(result.data); } };
Manage the integration
You can manage the Cloudflare Fauna integration from the Fauna Dashboard.
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!