@@ -34,33 +34,27 @@ In your Cloudflare dashboard, select **Edit Code** and add the following script
3434</Tip >
3535
3636``` javascript
37- addEventListener (" fetch" , (event ) => {
38- event .respondWith (handleRequest (event .request ));
39- });
40-
41- async function handleRequest (request ) {
42- try {
43- const urlObject = new URL (request .url );
44- // If the request is to the docs subdirectory
45- if (/ ^ \/ docs/ .test (urlObject .pathname )) {
46- // Then Proxy to Mintlify
37+ export default {
38+ async fetch (request ) {
39+ const url = new URL (request .url );
40+
41+ // Route /docs traffic to Mintlify
42+ if (url .pathname .startsWith (' /docs' )) {
4743 const DOCS_URL = " [SUBDOMAIN].mintlify.dev" ;
4844 const CUSTOM_URL = " [YOUR_DOMAIN]" ;
49-
50- let url = new URL (request .url );
45+
5146 url .hostname = DOCS_URL ;
52-
53- let proxyRequest = new Request (url, request);
54-
47+
48+ const proxyRequest = new Request (url, request);
5549 proxyRequest .headers .set (" Host" , DOCS_URL );
5650 proxyRequest .headers .set (" X-Forwarded-Host" , CUSTOM_URL );
57- proxyRequest .headers .set (" X-Forwarded-Proto" , " https" );
58-
59- return await fetch (proxyRequest);
51+
52+ return fetch (proxyRequest);
6053 }
61- } catch (error) {
62- // if no action found, play the regular request
63- return await fetch (request);
54+
55+ // Route all other traffic to your main site
56+ // Replace with your main site's URL
57+ return fetch (` https://your-main-site.com${ url .pathname }${ url .search } ` );
6458 }
6559}
6660```
0 commit comments