Control which routes invoke your Worker for Single Page Applications
For those building Single Page Applications (SPAs) on Workers, you can now explicitly define which routes invoke your Worker in Wrangler configuration. The run_worker_first
config option has now been expanded to accept an array of route patterns, allowing you to more granularly specify when your Worker runs.
Configuration example:
{ "name": "my-spa-worker", "compatibility_date": "2025-06-18", "main": "./src/index.ts", "assets": { "directory": "./dist/", "not_found_handling": "single-page-application", "binding": "ASSETS", "run_worker_first": ["/api/*", "!/api/docs/*"] }}
name = "my-spa-worker"compatibility_date = "2025-06-18"main = "./src/index.ts"
[assets]directory = "./dist/"not_found_handling = "single-page-application"binding = "ASSETS"run_worker_first = [ "/api/*", "!/api/docs/*" ]
This new routing control was done in partnership with our community and customers who provided great feedback on our public proposal ↗. Thank you to everyone who brought forward use-cases and feedback on the design!
To use advanced routing control with run_worker_first
, you'll need:
- Wrangler v4.20.0 and above
- Cloudflare Vite plugin v1.7.0 and above
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark