Skip to main content
On Cloudflare, the relay is a Worker on routes of your zone. The Worker sends each request on to your site. Thus, your site can run on any host. The code on this page is for the US region with Every page selected. Copy your code from the setup screen. It has your region and your paths.

Before you start

Create a Worker project. Then install @waniwani/relay 0.6.0 or later:

Steps

1

Write src/index.ts

src/index.ts
If a Worker already runs on these pages, add the if block at the top of its fetch handler.
2

Write wrangler.jsonc

Put your hostname in place of example.com:
wrangler.jsonc
3

Add the key and deploy

In the Worker folder, run these commands. When the first command asks for the key, paste the key from the setup screen.
4

Check

In the setup screen, enter the address of one of your pages and click Check now.

With agent pages or blocking

When the website serves agent pages or blocks an agent, the setup screen gives you this src/index.ts. It also calls serveAgentPage:
src/index.ts
On a path with an agent page, an AI agent gets that page from the Worker. A client that asks for Markdown also gets it. All other requests go to your site with no change. If a Worker already runs on these pages, copy each line above export default to the top of its file. Then add each line of the fetch handler, except return fetch(request), at the top of its fetch handler. You make this change one time. After it, you turn agent pages and blocking on and off in the dashboard, with no deploy.

Notes

  • waitUntil keeps the event alive after the response. Thus, the agent does not wait for it.
  • With Only some paths, the routes have your paths, and the Worker checks each path again with isChosenPage. A route can only end in *. Thus, /pricing* also matches /pricing-old. Also add the paths of your agent pages.
  • In the EU region, each call gets region: "eu".