๐ŸŒ Trying to reverse proxy to my documentation using routes and workers

I am trying to host documentation for my app on a path rather than on my subdomain. I thought I could accomplish this with cloudflare as follows:

In short, I want to use a worker to display my documentation site whenever a client goes to mydomain.io/docs* but goes to my main bubble application hosted at mydomain.io for all other requests.

Sadly, I canโ€™t get this to work.

Things that do work:

  • My bubble app is being proxied through cloudlfare
  • The worker script runs as expected when invoked from its workers.dev url
  • mydomain.io loads perfectly fine

However, when I visit mydomain.io/docs*, I get my bubbleโ€™s apps 404 page instead of triggering my worker.

Can anyone tell me why this is happening? Is there a configuration step I am missing to trigger the worker from mydomain.io/docs*?

Does it matter that Iโ€™m using an example domain in my post above rather than my actual domain? Let me know if thatโ€™s an issue and I can edit to include my actual domain name. In any case, everything else I said is accurate

It looks to me that Bubble uses Cloudflare, so whatโ€™s most likely happening is Bubble is intercepting a lot of your expected behaviors.

Hmm, that had been a thought that crossed my mind. I think thatโ€™s a root issue here now that you mention it. In that case I am going to reach out to Bubble to see what I can learn. Thank you for your message! Really a good pointer for me :slight_smile:

1 Like

are you resolving the fetch promise?

Try this code instead:

addEventListener('fetch', event => {
    event.respondWith(handleRequest(event.request))
})

const handleRequest = async (request) => {
	
	const docUrl = 'https://dynamicpackages.gitbook.io/v1/'
	const url = new URL(request.url)
	const {pathname} = url
	
	const response = await fetch(docUrl)

	if(response.ok)
	{
		return new Response(response.body, {
			headers: response.headers
		})
	}
	else
	{
		console.log({status: response.status, statusText: response.statusText})
		return Response.redirect(docUrl, 302);
	}
}

Just tried your recommended edit to the worker script - thank you for that tip!

Alas, it got me the same result. So I do think my issue lay on the Bubble side of this. I am still investigating. Even so, Thank you!

If Bubble intercepts the request, why not serving your documentation (momentarily) from a subdomain, using a dummy IP (e.g. 192.0.2.1) as the A record?

You could have your documentation available in a couple of minutes.

For some reason, theyโ€™re trying to avoid that.