Hi, We are trying to set up the following traffic pattern:
-all requests for www.site/blog{/}* are sent to the existing A record
-all requests for www.site{/path} are sent to https://site.webflow.io/{path}
I’ve written the following code. The blog loads correctly, but the Webflow site does not. What is wrong?
addEventListener(‘fetch’, event => {
event.respondWith(fetchBlog(event.request))
})
async function fetchBlog(request) {
const reqUrl = new URL(request.url)
if (reqUrl.pathname.startsWith(‘/blog’)) {
// Return response unmodified.
console.log(reqUrl.href)
return fetch(reqUrl, request)
} else {
let newUrl = new URL(‘https://site.webflow.io/’)
newUrl.pathname = reqUrl.pathname
console.log(newUrl.href)
return fetch(newUrl, {
method: request.method,
headers: request.headers
})
//return fetch (newUrl, request)
}
}