How to rewrite relative paths in href html elements or proxy them transparently

I’m trying to proxy a discourse blog on subdomain to my root domain /blog. But discourse servers a lot of files with relative links on it…examples:

<link rel="preload" href="/assets/browser-update-1741a2ed67a367faeb0a582af064457e8b1b1354e52e6efcf8bf26301166dec8.js" as="script">

<link href="/stylesheets/discourse-solved_2_d335db0449b9d3e518e949a991fe12b7c0af6ba3.css" media="all" rel="stylesheet" data-target="discourse-solved" data-theme-id="3" />

That of course causes chrome to try to load them using my root domain, which fails with error 404. How can I fix this? Preferably in a way I won’t expose my subdomain to google.

Current workers code:

addEventListener('fetch', event => {
  var url = new URL(event.request.url);
  if (url.pathname.startsWith('/blog/') || url.pathname === '/blog') {
    handleBlog(event, url);
  } else {
    event.respondWith(fetch(event.request));
  }
})

async function handleBlog(event, url) {
  var originUrl = url.toString().replace(
    'https://ultraluz.com.br/blog',
   'https://forum.ultraluz.com.br');
  event.respondWith(fetch(originUrl)); 
}

How can I use this to change relative paths in the href elements? Or add

<base href="https://example.com/" />

on the beginning of them