mgx

worker.js to put the ghost blog in the subdirectory of your main domain

If you follow Louis's instructions on this topic, you might get stuck on step 6. Paste the following script instead of the one on cloak.ist. Syntax fix - save for later.

const config = {
  subdomain: "blog.example.com",
  root: "example.com",
  blogPath: "blog",
};

async function handleRequest(request) {
  const url = new URL(request.url);
  const targetPath = url.pathname;
  let response = await fetch(`https://${config.subdomain}${targetPath}`);

  if (
    targetPath.includes(`/${config.blogPath}/favicon.png`) ||
    targetPath.includes(`/${config.blogPath}/sitemap.xsl`) ||
    targetPath.includes(`/${config.blogPath}/assets/`) ||
    targetPath.includes(`/${config.blogPath}/public/`) ||
    targetPath.includes(`/${config.blogPath}/content/`)
  ) {
    return response;
  }

  let body = await response.text();
  body = body.split(config.subdomain).join(config.root);
  response = new Response(body, response);
  return response;
}

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