title: Redirect from one domain to another in cloudflare workers does not work
body: <p>I need to configure that requests that match the domain1.com/test/<em>/</em> pattern be serviced by the domain2.com application.
  Tried to configure it as follows.
  Created a worker, added code</p>
  <p>'''</p>
  <pre><code>const redirectMap = new Map([
    ['/test1', 'domain2.com'],
  ])
  
  addEventListener('fetch', async event =&gt; {
    event.respondWith(handleRequest(event.request))
  })
  
  async function handleRequest(request) {
    let requestURL = new URL(request.url)
    let path       = requestURL.pathname.split('/redirect')[1]
      let location   = redirectMap.get(path)
  
    if (location) {
      return Response.redirect(location, 301)
    }
    
    return fetch(request)
  }
  </code></pre>
  <p>'''</p>
  <p>After that in the domain settings, I added a worker and specified the site domain1.com/test/*.
  But it did not work. Help please.
  Uses instructions <a href="https://www.cloudsavvyit.com/3660/how-to-create-a-cloudflare-worker-to-redirect-requests/" rel="nofollow noreferrer">https://www.cloudsavvyit.com/3660/how-to-create-a-cloudflare-worker-to-redirect-requests/</a></p>