How do I configure a Cloudflare Worker to respond to a specific URL?

Question

Grade: Education Subject: Support
How do I configure a Cloudflare Worker to respond to a specific URL?
Asked by:
68 Viewed 68 Answers

Answer (68)

Best Answer
(390)
You can configure a Cloudflare Worker to respond to a specific URL by creating a route in your Worker. In your `wrangler.toml` file, you define a `route` section that maps a URL pattern to a handler function. For example, a route `/api/users` would be mapped to the `handleApiUsers` function. You then define the function logic in `worker.js`. The URL matching is based on the path prefix.