Check out v4 of the Fauna CLI

v4 of the Fauna CLI is now in beta.

The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start.

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:

  1. Log in to the Cloudflare dashboard and select your account.

  2. In Account Home, select Workers & Pages.

  3. In Overview, select your Worker.

  4. Select Integrations > Fauna.

  5. Follow the setup flow and select your Fauna database.

  6. 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.

Manage authentication keys

To view authentication keys for an integrated Cloudflare Worker, select your database and click the Keys tab.

Keys for a Cloudflare Worker integration are prepended with _cloudflare_key_.

Key tab for a database in the Fauna Dashboard

You can delete the key to disable the integration.

Manage OAuth Apps

When you connect a Cloudflare Worker to your database, Fauna creates an OAuth client app in your Fauna account.

To view your account’s OAuth apps, go to Account > OAuth Apps in the Fauna Dashboard.

OAuth Apps in the Fauna Dashboard

You can delete the app to disable the integration.

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!