Passing Request URL to the HTMLRewriter

I’m trying to pass the URL Path into the title of the static website, so if the user is on example.pages.dev/Hello-World/ then the title of the page would be “Hello-World”

It seems like I’m missing something basic I’m just not sure how to pass the information to where it’s needed.

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

metatags = '<title>' + pathname + '</title>';

async function handleRequest(req) {
  
  // const res = await fetch(req);
  const { pathname } = new URL(req.url);
  const response = await fetch("https://example.pages.dev" +  pathname)
  const contentType = response.headers.get('Content-Type');
  
  // If the response is HTML, it can be transformed with
  // HTMLRewriter -- otherwise, it should pass through
  if (contentType.startsWith('text/html')) {
    return rewriter.transform(response, pathname);
  } else {
    return response;
  }
}

const rewriter = new HTMLRewriter()
   .on('title', {
      async element(node) {
         node.replace(metatags, { html: true });
      },
    })

I changed my approach and now I have it working on the worker - and on a test subdomain - perfect👍

:white_check_mark:test.example com works 100% correctly
:x:However, when I use it on example com to go live it doesn’t fire the worker.
The worker is shown as mapped in the DNS yet it doesn’t seem to execute ever.

The same worker on the test subdomain works flawlessly.
This is driving me insane, and I’m not sure where to begin troubleshooting.

I removed the URL pattern matching as I wanted it to fire in /accounts only - but I’m desperately attempting to get any kind of rise out of it. I will post my new - simpler code below.

This worker will rewrite the Title for each URL based on a Static HTML page using Regex Find and Replace.

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


async function handleRequest(req) {
  
  const { pathname } = new URL(req.url);
  const response = await fetch("https://example-static-html.pages.dev" +  pathname)
  const contentType = response.headers.get('Content-Type');

  metadata = '<title>Cool Example Post #'+ pathname +'</title>';
  metadata += '<meta property="og:url" content="https://example.com'+ pathname +'">';


 if(response.headers.has("Content-Type") && response.headers.get("Content-Type").includes("text/html")){

    const text = await response.text();
    let regex = /<title>Default Title<\/title>/;
			const modified = text.replace(new RegExp(regex), metadata);
			return new Response(modified, {
				status: response.status,
				statusText: response.statusText,
				headers: response.headers
			});
  } else {
    return response;
  }
}

Any help would be appreciated - how do I contact Cloudflare support? I have a paid account