worker routes in wrangler.toml

I'm having troubles understanding how routes works This works
routes = [{ pattern = "*/assetscdn/*", zone_id = "<zone_id>" }]
routes = [{ pattern = "*/assetscdn/*", zone_id = "<zone_id>" }]
This doesn't work ✘ [ERROR] Could not find zone for assetscdn
routes = [{ pattern = "*/assetscdn/*", zone_name = "<zone_name>" }]
routes = [{ pattern = "*/assetscdn/*", zone_name = "<zone_name>" }]
This doesn't work Route pattern may only contain wildcards at the beginning of the hostname and the end of the path: <domain>/*/assetscdn/*
routes = [{ pattern = "<domain>/*/assetscdn/*", zone_name = "<zone_name>" }]
routes = [{ pattern = "<domain>/*/assetscdn/*", zone_name = "<zone_name>" }]
This doesn't works ✘ [ERROR] Invalid URL
routes = [
{ pattern = "*", zone_id = "<zone_id>" },
{ pattern = "*/*", zone_id = "<zone_id>" }
]
routes = [
{ pattern = "*", zone_id = "<zone_id>" },
{ pattern = "*/*", zone_id = "<zone_id>" }
]
This work
routes = [
{ pattern = "*", zone_name = "<zone_name>" },
{ pattern = "*/*", zone_name = "<zone_name>" }
]
routes = [
{ pattern = "*", zone_name = "<zone_name>" },
{ pattern = "*/*", zone_name = "<zone_name>" }
]
Is there an implementation difference or I'm missing something?
7 Replies
kian
kian16mo ago
The top 3, with infix wildcards, are not supported
o0th
o0th16mo ago
All 3? Because in my test the first one works
kian
kian16mo ago
If you're trying to allow /assetcdn/* on all domains then it would - I'm just saying that example.com/*/assetscdn/* wouldn't be valid. Hence why the third doesn't work, I just assumed the two above were attempting to accomplish the same thing
Walshy
Walshy16mo ago
*/ would be all domains therefore it breaks due to a specified domain Then wildcards need to be at the start (above) or the end /* You'd need to just do example.com/assetscdn/* to serve everything under /assetscdn/*
o0th
o0th16mo ago
Alright this make sense for the 3rd one which is invalid, but why the first two are different?
o0th
o0th16mo ago
GitHub
workers-sdk/zones.ts at main · cloudflare/workers-sdk
⛅️ The CLI for Cloudflare Workers®. Contribute to cloudflare/workers-sdk development by creating an account on GitHub.
o0th
o0th16mo ago
But I don't understand why you need zone_name if you have zone_id to get the host, or maybe I'm missing something