Two Workers + Same Domain + Route Conflicts
I have two Workers that need to share the same domain with path-based routing:
- Site Worker: Should handle sub.domain.com/* (everything except API)
- API Worker: Should handle sub.domain.com/api/* (API endpoints only)
Current wrangler configs:
Site worker:
"routes": [
{ "pattern": "sub.domain.com", "zone_name": "domain.com" },
{ "pattern": "sub.domain.com/", "zone_name": "domain.com" },
{ "pattern": "sub.domain.com/!(api)/", "zone_name": "domain.com" }
]
API worker:
"routes": [
{ "pattern": "sub.domain.com/api/", "zone_name": "domain.com" }
]
Problem:
- sub.domain.com/ →
Works (site worker)
- sub.domain.com/api/ →
404 (should hit API worker)
What we've tried:
-
Both workers deploy successfully
-
Individual subdomains work (api.sub.domain.com)
-
Adding API routes breaks subdomain routing entirely
-
Removing routes from API worker temporarily fixes subdomain but no path routing
-
Different route pattern combinations
Both workers deploy successfully, but API routes return 404. Do I need to remove custom domains from one worker? Is the route pattern syntax correct for excluding /api/* from the site worker?
Any guidance on proper multi-worker routing appreciated!
- Site Worker: Should handle sub.domain.com/* (everything except API)
- API Worker: Should handle sub.domain.com/api/* (API endpoints only)
Current wrangler configs:
Site worker:
"routes": [
{ "pattern": "sub.domain.com", "zone_name": "domain.com" },
{ "pattern": "sub.domain.com/", "zone_name": "domain.com" },
{ "pattern": "sub.domain.com/!(api)/", "zone_name": "domain.com" }
]
API worker:
"routes": [
{ "pattern": "sub.domain.com/api/", "zone_name": "domain.com" }
]
Problem:
- sub.domain.com/ →
- sub.domain.com/api/ →
What we've tried:
-
-
-
-
-
Both workers deploy successfully, but API routes return 404. Do I need to remove custom domains from one worker? Is the route pattern syntax correct for excluding /api/* from the site worker?
Any guidance on proper multi-worker routing appreciated!
