Parse request from specific past to other subdomain

Currently my worker ( requests to “” - this brings up some CORS issues + I expose my API.

I was wondering if you could somehow write a worker script that would check if /wp-json/ was included in the path, and then request

So if I made a request to:

It would return contents from:

This way URLs would be cleaner plus I believe I could avoid annoying CORS issues.

Yes that’s defiently possible. This is how I achieved it.

async function handleEvent(event) {
  const url = new URL(event.request.url)

	if (url.pathname.includes('wp-json') || url.pathname.includes('api/') || url.pathname.includes('wp-content/')) {
		url.hostname = '';
		if (url.pathname.includes('api/')) {
			url.pathname = url.pathname.replace('api/', 'wp-json/');
		return await fetch(url, event.request);

The API is 50% faster now because of no CORS issues.