Course lesson 16 · Smart Routing Service

Geo based smart routing

One study unit · Read, recall, then practice · Original video 00:11:50

This lesson turns the data-service lookup into an actual redirect. It validates the relevant Cloudflare metadata, chooses a country-specific destination when configured, and otherwise chooses the default URL. A small routing helper holds the selection logic while the Hono route coordinates lookup, error handling, and the redirect response.

Primary source: course video 16 · Supplied English subtitles · 00:11:50.

Understand the idea

What the course does

  1. Add not-found handling for a link ID with no configuration.
  2. Define or inspect the shared Cloudflare-info schema and parse the cf metadata with it.
  3. Add a routing helper that checks the country mapping and falls back to the default destination.
  4. Replace the temporary JSON result with Hono’s redirect response.
  5. Set a known default destination in the dashboard and test the redirect locally, then deploy the data service.
  6. Use the instructor’s VPN experiment: configure Malaysia with an alternate destination and verify the deployed redirect changes when that country is detected.

Watch for

Recall before revealing

What destination is chosen for a valid link when its country is absent or has no override?

Reveal the explanation

The routing helper chooses the default destination; a failure to parse the entire metadata object follows a separate error path in the demonstrated route.

Try it

Predict and test three cases: a configured country, an unconfigured country, and a missing link ID.

Check your result

The configured country uses its override, the unconfigured country uses the default, and the missing link receives a not-found response.

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.

Companion primary documentation: Hono on Cloudflare Workers. For recorded API names, commands, limits, and prices, check the version you use.

← Previous   Next →