Course lesson 12 · Smart Routing Service
Setting up the Data Service
The course now moves from the dashboard’s lightweight backend to the separate data service. Its first responsibility is receiving a short-link ID and redirecting the visitor to a default or country-specific destination. The lesson starts with a minimal WorkerEntrypoint class, explaining event handlers and deploying a hello-world response before adding routing complexity.
Primary source: course video 12 · Supplied English subtitles · 00:07:20.
Understand the idea
- The public redirect service is separate from the dashboard service, even though both use the same link configuration.
- Country-based routing requires a link’s destination map and location information attached to the incoming request.
- A WorkerEntrypoint class and a module exporting a fetch handler can both handle HTTP requests in the patterns shown.
- Fetch, queue, and scheduled handlers correspond to different trigger types that invoke application code.
- The class constructor provides a common initialization location before the class handles its event, which later lessons use for shared dependencies.
What the course does
- Inspect the dashboard’s default destination and optional country overrides to define the required routing behavior.
- Open the data-service application and locate its source entrypoint and minimal fetch response.
- Compare the class-based entrypoint with the user application’s module-style Worker entrypoint.
- Inspect the available fetch, queue, and scheduled methods and discuss their trigger roles.
- Run the data service locally on the demonstrated port 8787, then deploy it using its simple Wrangler script.
- Open the deployed data-service URL and confirm hello world before introducing Hono.
Watch for
- Generated short URLs currently include an undefined hostname because their frontend Vite variable has not been configured yet; this is expected at this stage.
- The class-based style is the instructor’s organizational preference rather than a requirement for all Workers.
- Added advice: request-location information is an input to routing, not proof of someone’s identity or exact physical position.
Recall before revealing
Why establish a working hello-world deployment before adding the redirect logic?
Reveal the explanation
It confirms the data service’s entrypoint and deployment setup independently, making later failures easier to attribute to the new functionality.
Try it
Run and deploy the data service, then name one responsibility that belongs here and one that stays in the user application.
Check your result
Both local and hosted URLs respond, and you assign public redirecting to the data service and link editing to the user application.
Practice prompts and answer checks are added teaching material. Answer from memory first, then compare and explain any difference.
Rewatch only what you need
Open this lesson in your original course library and seek to the times below. Videos are not hosted on this site.
- 00:00:00 — Default and country-specific redirect requirements
- 00:02:00 — Move into the separate data service
- 00:04:01 — Worker triggers
- 00:05:01 — Constructor and local startup
- 00:06:01 — Deploy the minimal service
Companion primary documentation: Cloudflare resource bindings. For recorded API names, commands, limits, and prices, check the version you use.