Multiple workers at the same domain, but multiple paths in wrangler.jsonc

I am trying to setup multiple workers at api.mydomain.com with different paths, but am not sure how to configure the routes section in wrangler.jsonc I want my worker’s APIs to be available at api.mydomain.com/worker. But if I set that in the routes array in wrangler.jsonc like this:
"routes": [
{
"pattern": "api.mydomain.com/worker1/*",
"zone_name": "mydomain.com"
}
]
"routes": [
{
"pattern": "api.mydomain.com/worker1/*",
"zone_name": "mydomain.com"
}
]
It doesn’t work because there is no DNS record set up for api.mydomain.com. If I define a custom domain as part of the routes like this:
"routes": [
{
"pattern": "api.mydomain.com",
"custom_domain": true
},
{
"pattern": "api.mydomain.com/worker1/*",
"zone_name": "mydomain.com"
}
]
"routes": [
{
"pattern": "api.mydomain.com",
"custom_domain": true
},
{
"pattern": "api.mydomain.com/worker1/*",
"zone_name": "mydomain.com"
}
]
My API becomes available at api.mydomain.com, which is not what I want. Also, api.mydomain.com/worker1 routes never work, no matter what variations I try. Can anyone tell me what configuration I need to set to make my API available at a specific path of api.mydomain.com?
1 Reply
Walshy
Walshy2mo ago
Use 2 routes rather than a custom domain api.mydomain.com/* and api.mydomain.com/worker1/*

Did you find this page helpful?