Troubleshooting Cloudflare Worker Redirect to Specific Server Path

I’m reaching out for assistance with an issue I’m facing with my Cloudflare Worker. The Worker is supposed to redirect requests from its URL to a specific path on my server, but it’s not functioning as expected.

Details:

  • Worker URL: https://server.kisoft.workers.dev
  • Expected Redirect Target URL: https://files.kisoft.net:8443/testRoute
  • Issue: When I access https://server.kisoft.workers.dev, I expect it to redirect to https://files.kisoft.net:8443/testRoute. However, this redirection is not occurring, despite the direct access to https://files.kisoft.net:8443/testRoute working correctly when visited directly in the browser.

Cloudflare Worker Script:

Here’s the Cloudflare Worker script I am utilizing:

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

async function handleRequest(request) {
  const url = `https://files.kisoft.net:8443/testRoute`;
  const response = await fetch(url);
  return response;
}

What I’ve Tried:

  • I’ve confirmed the URL specified in the Worker script is correct.
  • Direct access to the URL https://files.kisoft.net:8443/testRoute successfully displays the expected content.
  • The issue seems to be specific to how the Worker handles the redirect.

Questions:

  1. Are there specific configurations or nuances in setting up Cloudflare Workers for redirecting to specific server paths that I might have missed?
  2. Could there be settings within the Cloudflare dashboard that are affecting the Worker’s ability to correctly redirect to the specified path?

Your insights or any suggestions for resolving this issue would be greatly appreciated. I am happy to provide further information or clarification as needed.

Thank you for your support.

Hi there,

For Redirects, shouldn’t it be similar to :

Thank you.

Hello,
Thank you for your suggestion. I’ve tried implementing the redirect functionality, and while it successfully reroutes the requests, it unfortunately does not address my need to cache the responses. Caching is very important in my case as it directly impacts the performance and efficiency of the service I’m providing.

As someone who’s relatively new to Cloudflare workers, I’m surprised to encounter this hurdle with what seems like a fundamental capability. I feel that I might be overlooking a crucial detail or perhaps there’s a gap in my understanding. If you have any insights into how I can achieve both redirection and caching, or if there’s an alternative approach I should consider, I would greatly appreciate your guidance.

Thank you once again for your time and assistance.

Best regards