WP Admin login issue with worker process for /blog subdomain

I have a website (say xyz. com) and had my blog on a subdomain on separate server (blog.xyz. com)
for SEO reasons we wanted xyz. com/blog to be our blog url in place of the subdomain. So I created a worker process (see code below)
This basically does a reverse proxy and when user requests xyz. com/blog/* - it gets the content from blog.xyz. com/* and serves it . This works perfectly well with all requests
We have setup our WP url as xyz. com/blog

The issue that we are having is that we are unable to login to the WP Admin backend any more
if we go to blog.xyz. com/wp-admin or xyz. com/blog/wp-admin and put in the WP login information , it just refreshes the page. My guess is this is happening because of the browser cookies being dropped for WP login. Has anyone seen this before and have a potential solution for it?

Worker process code:
addEventListener(‘fetch’, event => {
var url = new URL(event.request.url);
if (url.hostname.toLowerCase() == “blog.xyz. com”)
{
event.respondWith(HandleSubdomain(event,url));
}
else
{
if (url.pathname.startsWith(’/blog/’) || url.pathname === ‘/blog’) {
handleBlog(event, url);
} else {
event.respondWith(fetch(event.request));
}
}
})

async function handleBlog(event, url) {
console.log(‘incoming:’ + url.toString());
var originUrl = url.toString().replace(
https://xyz. com/blog’,
https://blog.xyz. com’);
//Add a querystring to the url

//Add a querystring to the url
if (url.toString().indexOf("?") > -1 )
{
//Url already has querystring
originUrl = originUrl + “&CloudFlare=1”;
}
else{
originUrl = originUrl + “?CloudFlare=1”;
}

event.respondWith(fetch(originUrl));
}

async function HandleSubdomain(event,url)
{
console.log(“subdomain:” + url.toString());
if (url.toString().indexOf(“CloudFlare=1”) > -1)
{
console.log(‘contains cloudFlare’);
const response = await fetch(url)
return response
}
else{
console.log(‘no cloudflare’);
var newUrl = url.toString().replace(
https://blog.xyz. com’, ‘https://xyz. com/blog’);
console.log('redirect to ’ + newUrl);
return Response.redirect(newUrl, 301);

}
}

Have you tried using wrangler tail to debug this? Adding some console.log statements to your worker code and then testing a login via the browser should allow you to seen which parts of your code are impacting the login so you can debug it:

https://developers.cloudflare.com/workers/learning/debugging-workers