Prevent Cloudflare Workers form Running on Query URL (?)

I have several Cloudflare workers and understand how to create a Bypass… however, you are not allowed to bypass on query urls such as “?ajac-wc”. Simultaneously, running my workers on this url breaks my call to Ajax on Woocommerce… So for now, I have set my workers to run on every single letter of the alphabet like so (but there has to be a better way; no?)

Maybe if you could do something inside a Worker script to check and look up the URI, therefore exclude the particular query part, for example if it contains ?ajax-wc then don’t run/call the function, else run/call it to do something :thinking: Like, check if it contains, then parse in case if there are multiple, or we just need one particular here, skip running the function.

Maybe some idea with:

async function handleRequest(request) {
  const { wpajax } = new URL(request.url)
  let wc = searchParams.get('ajax-wc')
  //console.log(wc)
}

Or, rather

if (url.pathname.includes("?ajax-wc")) {
  // call the function
else{
  // do nothing
}

However, there might be as stated, multiple parameters and above would break, so we should use (I haven’t tested yet):

if (url.searchParams.has("ajax-wc")) {
  // do something
else{
  // do nothing
}

Kindly wait for another reply, it’s 4.30AM by me and I can test this later today, have to go to get some rest now :sweat_smile: :zzz:

1 Like

Thank you, now I wonder which would be more efficient in regards to speed. My alphabet, or a url check inside of the worker. Get some rest! :slight_smile:

1 Like

Your wildcards will still allow me to do something like example.com/zebra?ajac-wc and the worker will still run, which it sounds like is not what you want.

I would definitely recommend checking this within your worker itself as @fritex suggested.

Good point Cherry, the main purpose of this was to stop the Worker from running on /?ajax-wc as it was breaking the cart feature in woocommerce. So running on other queries is actually fine. But it did seem a little excessive.

1 Like

To confirm, this actually will not work - and the reason is because ajax-wc is being “fetched” instead of loading as the main url. The main url remains /checkout.