Fetching external sitemap.xml no response
# workers-help
o
Hi there, I'm trying to use cloudflare worker to change the instances of hostname of a sitemap that is generated by Webflow. We have to use this method as our webflow is reverse-proxied but Webflow customization is a bit lacking and won't use the global canonical URL in the auto-generated sitemap.xml. Gist of what I'm doing is fetching the actual webflow sitemap.xml, replacing all instances of the hostname with what we want to be user-facing and SEO-facing, serving the modified sitemap.xml. I'm having an issue where cloudflare worker is getting no response when fetching. The sitemap resource is public and works fine in postman GET.
Copy code
async function handleSitemap() {
  const sitemapUrl = 'https://tempsite.com/sitemap.xml'
  
  const headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36',
    'Accept-Language': 'en-US,en;q=0.9'
  }

  let response = await fetch(sitemapUrl, {method: 'GET', headers: headers})
  console.log(response.body)

  if (!response.ok) {
    throw new Error('No response!')
  }
  
  let data = await response.text()
  const contentType = response.headers.get('content-type')

  // Replace 'tempsite.com' with 'mysite.com'
  data = data.replace(/tempsite\.com/g, 'mysite.com')

  return new Response(data, {
    headers: {
      'content-type': contentType
    }
  })
}

https://cdn.discordapp.com/attachments/1109174734966493274/1109174735109111820/image.png

mm may actually just be an issue with the debug console in webflow...seems to actually work fine in prod