Setup Steps
- Create a new Cloudflare Worker at
Workers & Pages > Create application > Create worker
- Add your custom domain by going to
Settings > Triggers > Add Custom Domain
- Add both
domain.com and www.domain.com versions
- Click
Edit Code and paste the following script:
Replace [SUBDOMAIN] and [YOUR_DOMAIN] in DOCS_URL and CUSTOM_URL with your values
addEventListener("fetch", (event) => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
try {
const urlObject = new URL(request.url);
// If the request is to the docs subdirectory
if (/^\/docs/.test(urlObject.pathname)) {
// Then Proxy to Mintlify
const DOCS_URL = "[SUBDOMAIN].mintlify.dev";
const CUSTOM_URL = "[YOUR_DOMAIN]";
let url = new URL(request.url);
url.hostname = DOCS_URL;
let proxyRequest = new Request(url, request);
proxyRequest.headers.set("Host", DOCS_URL);
proxyRequest.headers.set("X-Forwarded-Host", CUSTOM_URL);
proxyRequest.headers.set("X-Forwarded-Proto", "https");
return await fetch(proxyRequest);
}
} catch (error) {
// if no action found, play the regular request
return await fetch(request);
}
}
- Click
Deploy (changes may take a few hours to propagate)
Need help? Contact our support team