Cloudflare worker route priority/order?

Is there a recommended practice or method to maintain or prioritize worker routes? Or, is there another mechanism at play that determines which worker gets run?

Now that multiple workers are available outside of enterprise this is becoming a priority. Before I used to have a secondary routing mechanism inside of a single worker but modular workers are far more desirable. However I need to maintain route stability, particularly in production.

Example the UI reflects:
route: /* worker: DeliverAWorkerSite
route: /stuff/* worker: DoStuff

Unlike page routes, /stuff is detected first which is a good thing but am looking for understanding/consistency/official policy? Otherwise I’ll need to continue to embed multiple mini workers inside of one and utilize custom routing to ensure such.

Any help guidance would be appreciated.

They seem to sort themselves automatically. At least that’s how it looks when I have multiple routes, added in no particular order.

1 Like

Automatically by most restrictive? If so, fancy!

1 Like

Typically this is done by trying to find the most applicable match, which often simply means taking the longest string (/stuff/* is longer than /*).

Though I cannot definitively confirm this is the case here too and Cloudflare isn’t doing some additional voodoo. Only the usual suspects could officially confirm that, @harris @KentonVarda @sklabnik :slight_smile:

1 Like

Understood and yeah, that’s what I’m looking for, that definitive answer. A convention when undocumented is so so scary :wink: Not saying that its not documented, just couldnt find it and page rules operate differently. That and the UI changes after you add one and refresh. So scary :wink:

Thank you all, looking forward to the official answer but in the mean time the convention of the most restrictive based potentially on length is working so far so we’ll keep the next release modular vs custom routing inside one god worker.

Well, Cloudflare is not exactly pulling an MSDN or Javadoc standard :smile:. So yes, there is a lot which is not fully documented.

Though, I am afraid only one of the three tagged people will be able to definitively confirm how the internal path matching is working.

1 Like

Not sure how I missed this or if its new :wink: Would still love to know how most specific is determined but this is plenty to go on. Thank you Cloudflare Team and Community!

“When more than one route pattern could match a request URL, the most specific route pattern wins. For example, the pattern* would take precedence over ** when matching a request for .”

1 Like