Presence of query string make route match fail

workers

#1

I have a worker that changes the origin for a few routes on our homepage to point to our new marketing site. The routes similar following:
https://disclosures.io/
https://disclosures.io/product/*

When I navigate to the root without query string params the worker is activated correctly. However, if a query string such as a utm value is present (i.e. https://disclosures.io/?utm=campain) the route match no longer works.

Is this a bug or am I doing something wrong?


#2

I have query string params on my workers and they work fine.
Maybe the worker code:
try adding route, if it doesn’t work can you add part of your code here.
https://disclosures.io/?*


#3

I get the following error when trying to add query string params.

Route pattern should not have query parameters https://disclosures.io/?*

I should also note that query strings work with my wildcard rule under the product directory. It seems like something about matching the root path exactly.

My worker code is the following:

addEventListener('fetch', event => {
  const request = event.request
  const url = new URL(event.request.url)

  if (url.hostname === 'stage.disclosures.io') {
    url.hostname = 'disclosures-stage.netlify.com'
  }
  
  if (url.hostname === 'disclosures.io' || url.hostname === 'www.disclosures.io') {
    url.hostname = 'disclosures-prod.netlify.com'
  }
  
  const args = {
    method: request.method,
    headers: request.headers
  }

  if (request.method === 'PUT' || 'POST') {
    args.body = request.body
  }
  return event.respondWith(fetch(new Request(url, args)))
})

#4

Hi played here:
https://cloudflareworkers.com/#aafee41f010f958c1d06bea3c6f97efa:https://disclosures.io/?utm=campaign

maybe route:
https://disclosures.io/*