Here is how to connect Verbolia pages to your Cloudflare application.
Notes: Always replace “client.com” with your hostname, “client.backend.verbolia.com” with the given verbolia hostname and “/path_to_verbolia/” with the agreed routed url pattern.
- On your dash.cloudflare.com UI, go to Workers Routes and then click Manage Workers
- Click Create application, and then Created Worker, set a name, “reverse-proxy-verbolia” and click Deploy (The code will be copied in a later stage)
- Click Edit code, copy/paste the code (at the bottom of this page) in the editor (left side – don’t forget to adapt the “const ORIGINS” parameters) and click Save and deploy
- Go back to Worker Routes page and click Add route
- Put your hostname followed by the agreed route pattern in Route, choose “reverse-proxy-verbolia” in Worker and click Save
async function handleRequest(request) {
let url = new URL(request.url)
// Check if incoming hostname is
// a key in the ORIGINS object
let target = ORIGINS[url.hostname]
// If it is, proxy request to that third party origin
if (target) {
url.hostname = target
return fetch(url, request)
}
// Otherwise, process request as normal
return fetch(request)
}
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* An object with different url's to fetch
* @param {Object} ORIGINS
*/
const ORIGINS = {
'www.client.com': 'client.backend.verbolia.com',
}