Skip to content
Last updated

Setting up a Reverse Proxy in Cloudflare

⚠️ Warning: This guide provides a general overview of the configuration process. Technical requirements vary by environment; always consult your internal IT or security teams before applying these settings. If you would like to complete this setup with a Foleon technical expert, please contact Foleon Support or your Customer Success Manager.

1. Adding your domain into Foleon

  • login to Foleon
  • go to "Domains" in the Admin Console (or your workspace)
  • Use HTTPS protocol to ensure End to End encryption
  • Click "Create new Domain"
  • Fill in the domain
  • Click the checkbox for reverse proxy
  • (optional) enter your certificate details
  • Click "save"
domains.gif

2. Creating a worker in Cloudflare

We will create a small background script (Worker) that invisibly retrieves content from Foleon when a user visits your chosen path.

  • Log in to your Cloudflare Dashboard.
  • In the left sidebar, click "Workers & Pages".
  • Click the blue "Create Application" button.
  • Click "Create Worker".
  • Name the worker foleon-proxy (or similar) and click "Deploy".
  • Click "Edit Code".

Delete all existing code in the left-hand editor and paste the code block below exactly as is:

export default {
  async fetch(request, env) {
    const sourceUrl = new URL(request.url);
    const targetOrigin = env.FOLEON_TARGET; // "https://s1.us.foleon.com" OR "https://s1.foleon.com"
    const targetUrl = new URL(`${sourceUrl.pathname}${sourceUrl.search}`, targetOrigin);
    
    const forwardedHost = env.PUBLIC_HOST || sourceUrl.hostname;
    
    const newHeaders = new Headers(request.headers);
    newHeaders.set("X-Forwarded-Host", forwardedHost);
    newHeaders.set("X-Forwarded-Proto", "https");

    const newRequest = new Request(targetUrl, {
      method: request.method,
      headers: newHeaders,
      body: request.body,
      redirect: "manual"
    });

    try {
      return await fetch(newRequest);
    } catch (e) {
      return new Response("Proxy Error: " + e.message, { status: 502 });
    }
  }
}

3. Configuring the worker

By default, the script works automatically. However, you can add Environment Variables if you need to override the host (e.g., if you are testing on a staging URL but want to load production content).

  • Go back to the Worker overview page (click the < arrow in the top left).
  • Go to the Settings tab > Variables.
  • Under Environment Variables, click Add Variable to set the following:
Variable NameValue ExampleDescription
PUBLIC_HOSTyourdomain.com(Optional) Forces a specific domain to be sent to Foleon. Useful if testing on workers.dev URLs.
FOLEON_TARGEThttps://s1.foleon.comREQUIRED Change the destination server.
US: https://s1.us.foleon.com
EU: https://s1.foleon.com

4. Routing Traffic to the Worker

Now we need to tell Cloudflare to use this script only for your specific folder (e.g., /publications/), leaving the rest of your site untouched.

  • Go back to the "Workers & Pages" dashboard and click on your new "foleon-proxy" worker (or what you've called the worker).
  • Click the Settings tab near the top.
  • Add a domain under section "Domains & Routes"
  • Choose "Route"
  • Zone: Select your main domain (e.g., yourdomain.com).
  • Route: Enter the path you want to use followed by /*.
    • Example: yourdomain.com/publications/*
    • IMPORTANT: Ensure you include the www. if your site uses it.
  • Click Add Route.

5. Apply a domain to a project

  1. Login to foleon.

  2. Go to project settings.

  3. Select the newly created domain.

  4. Setup the basepath / subfolder you want to use to publish your documents on.

  5. Make sure to publish a document in this project.

You can setup multiple projects with the same basepath. e.q. /en/guide/finance/ and /en/guide/legal/