All guides

Set up Selvio with a Cloudflare Worker

For any site behind Cloudflare: deploy a small Worker and route /compare* on your domain to it.

Where the rule goes

This works for any site whose DNS is on Cloudflare with the records proxied (orange cloud). In the Cloudflare dashboard, create a Worker, replace its code with the code below, and deploy it. With Wrangler, put the code in worker.js and declare the route in wrangler.toml: routes = [{ pattern = "example.com/compare*", zone_name = "example.com" }].

The rule

For example.com, with the pages under /compare/. In the dashboard, the same rule is already filled in with your domain and path: copy it from there. If your pages exist in several languages, it has one more block per language (/fr/compare/…).

worker.js
// Selvio: the comparison pages of example.com, served by Selvio.
// Deploy as a Worker, with a route on your domain for each path below (see the guide).
const ROUTES = [
  {
    "root": "/compare",
    "prefix": "/compare/",
    "destination": "https://pages.selvio.io/_h/example.com/compare/"
  }
];

export default {
  async fetch(request) {
    const url = new URL(request.url);
    for (const r of ROUTES) {
      const match =
        url.pathname === r.root ? '' : r.prefix && url.pathname.startsWith(r.prefix) ? url.pathname.slice(r.prefix.length) : null;
      if (match !== null) {
        return fetch(r.destination + match + url.search, { method: request.method, headers: request.headers, redirect: 'manual' });
      }
    }
    return fetch(request);
  },
};

After

Deploy the Worker, then add a route to it on your domain: example.com/compare*. If the site also answers on www, add www.example.com/compare*. The pattern covers /compare and everything under it; the Worker passes any other path to your site unchanged.

Check

Open https://example.com/compare/_selvio/proxy-check in a browser, or run this command. The address must answer 200 with this text: selvio-proxy example.com.

Terminal
curl -i https://example.com/compare/_selvio/proxy-check

Then click I deployed it, check in the dashboard: it reads the same address on your domain. The check works before anything is published.

Common pitfalls

The people leaving your competitor will read a page. Make it yours.

Enter your site: Selvio picks up your brand style, suggests your competitors and checks their prices.

Free, no credit card. Nothing goes live without you.