Skip to content

Custom Domain vs Routes in Cloudflare Workers

When deploying Cloudflare Workers and connecting them to your own domain, Cloudflare offers two primary configuration methods within the wrangler.jsonc file or the dashboard: Custom Domains and Routes.^[001-TODO__Cloudflare_Workers_自架短網址_-_10_分鐘完工教學.md]

Custom Domain

The Custom Domain method directs the entire domain to be handled by the Worker.^[001-TODO__Cloudflare_Workers_自架短網址_-_10_分鐘完工教學.md]

  • Scope: The entire domain is served by the Worker.
  • Use Case: This is the recommended approach for services like a URL shortener where the application controls the entirety of the traffic for that specific hostname.^[001-TODO__Cloudflare_Workers_自架短網址_-_10_分鐘完工教學.md]
  • Configuration: Setting this up typically involves configuring the routes property in wrangler.jsonc and defining a zone; Cloudflare automatically manages the underlying DNS and SSL certificates.^[001-TODO__Cloudflare_Workers_自架短網址_-_10_分鐘完工教學.md]

Routes

The Routes method allows for more granular control by intercepting only specific paths or patterns.^[001-TODO__Cloudflare_Workers_自架短網址_-_10_分鐘完工教學.md]

  • Scope: Only matches specific paths (e.g., /api/* or a specific route pattern).
  • Use Case: Ideal for injecting Workers into an existing website without replacing the entire site, such as proxying specific API endpoints while a static site generator handles the main UI.
  • Configuration: Can be added via wrangler.jsonc or manually in the dashboard under Worker → Settings → Domains and Routes → Add.^[001-TODO__Cloudflare_Workers_自架短網址_-_10_分鐘完工教學.md]

Summary Comparison

Feature Custom Domain Routes
Target Entire domain Specific paths
Typical Use Dedicated apps (e.g., Shortener) Hybrid/Partial implementations
Recommendation Preferred for new projects Preferred for integrating with legacy sites

Sources

  • 001-TODO__Cloudflare_Workers_自架短網址_-_10_分鐘完工教學.md