Back to docs
Publishing Your Pages

Cloudflare Worker Setup

How to set up a Cloudflare Worker to route traffic to Flint for folder on main domain integration.

Prerequisites

  • A Cloudflare account (free tier is sufficient)
  • Your domain DNS must be managed through Cloudflare (DNS records set to Proxied/orange cloud)
  • Your Flint subdomain (contact the Flint team if you do not know this value)

Setup Steps

Step 1: Ensure your root domain DNS is proxied in Cloudflare

In your Cloudflare account, confirm that the DNS record for your root domain is set to Proxied (orange cloud). This proxied setting is required for the Cloudflare Worker to intercept and route requests.

Step 2: Create a Cloudflare Worker

In Cloudflare, go to Workers and Pages and create a new Worker. Name it flint-router. Use the following worker code:

javascript
const FLINT_SUBDOMAIN = "[your-flint-subdomain].tryflint.com";

export default {
  async fetch(request) {
    const url = new URL(request.url);
    const flintUrl = new URL(url.pathname + url.search, "https://" + FLINT_SUBDOMAIN);

    const proxyRequest = new Request(flintUrl.toString(), request);
    proxyRequest.headers.set("Host", FLINT_SUBDOMAIN);
    proxyRequest.headers.set("X-Forwarded-Host", url.hostname);
    proxyRequest.headers.set("X-Forwarded-Proto", "https");

    const response = await fetch(proxyRequest, { redirect: "manual" });
    const newResponse = new Response(response.body, response);

    const location = newResponse.headers.get("Location");
    if (location) {
      try {
        const locationUrl = new URL(location, flintUrl);
        if (locationUrl.hostname === FLINT_SUBDOMAIN) {
          locationUrl.hostname = url.hostname;
          locationUrl.protocol = url.protocol;
          newResponse.headers.set("Location", locationUrl.toString());
        }
      } catch {
        // Non-URL location header, pass through as-is
      }
    }

    return newResponse;
  },
};

Replace [your-flint-subdomain] with the Flint subdomain allocated to you by the Flint team.

Step 3: Add a Worker Route

After deploying the Worker, add a route to specify which pages or folders on your domain should be handled by the Worker. For example, to route all traffic under /lp/ through Flint, set the route to yourdomain.com/lp/*. Only requests matching the route will be proxied to Flint — all other traffic continues to your origin as normal. Set the failure mode to Fail open so that if the Worker encounters an error, requests fall through to your origin rather than returning an error to visitors.