Streaming live at 10am (PST)

Cloudflare Workers and Webflow

Hi there, I want to create additional routers (pages) with Cloudflare Workers on Webflow website.
I works great on different CMS, but with Webflow it’s quite harder.

I find some examples of code for Webflow - but it’s don’t. Can somebody help me please?

addEventListener(‘fetch’, event => {

event.respondWith(handleRequest(event.request))

})

async function handleRequest(request) {

//1. Parse the URL to get some useful info

let parsedUrl = new URL(request.url)

let pathStripped = parsedUrl.pathname.replace(/^(.+?)/*?$/, “$1”)

//2. Webflow URL to forward your pages to

var forwardHost = “example.com/category/

//3. Paths you’d like to match and forward

var urlPatterns = ["/category/*"]

//4. Match the routes, and forward the request

if (urlPatterns.some(pattern => (new RegExp(convertToRegexString(pattern))).test(pathStripped))) {

return await fetch(forwardHost + parsedUrl.pathname, request)

}

//5. Return deafult response

const response = await fetch(request)

return response

}

function convertToRegexString(pattern) {

//Escape Regex expression

pattern = pattern.replace(/[|\{}()^$+*?.-]/g, ‘\$&’)

//Build Regex string

return “^” + pattern.replace(/\*/g, ‘.*’).replace(/\?/g, ‘.’) + “$”

}


Here is my site Read-Only: LINK
(how to share your site Read-Only link)