I have a site: my-site.com and wordpress blog - mysiteblog.com. I use a worker to render the blog on my site domain in the subfolder: my-site.com/blog. All work fine, only wp-admin not work, I think the problem is at browser session. Do you have any suggestion?
My routes: www.my-site.com/blog*
My index.js
// keep track of all our blog endpoints here
const my Blog = {
hostname: “mysiteblog.com”,
targetSubdirectory: “/blog”,
assetsPathnames: ["/public/", “/assets/”]
}
async function handleRequest(request) {
// returns an empty string or a path if one exists
const formatPath = (url) => {
const pruned = url.pathname.split("/").filter(part => part)
return pruned && pruned.length > 1 ?${pruned.join("/")}
: “”
}
const parsedUrl = new URL(request.url)
const requestMatches = match => new RegExp(match).test(parsedUrl.pathname)
// if its blog html, get it
if (requestMatches(myBlog.targetSubdirectory)) {
console.log("this is a request for a blog document", parsedUrl.pathname)
const targetPath = formatPath(parsedUrl)
const query = parsedUrl.search
return fetch(`https://${myBlog.hostname}/${targetPath}${query}`)
}
// if its blog assets, get them
if ([myBlog.assetsPathnames].some(requestMatches)) {
console.log("this is a request for blog assets", parsedUrl.pathname)
const assetUrl = request.url.replace(parsedUrl.hostname, myBlog.hostname);
return fetch(assetUrl)
}
console.log("this is a request to my root domain", parsedUrl.host, parsedUrl.pathname);
// if its not a request blog related stuff, do nothing
return fetch(request)
}
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})