Course lesson 14 · Smart Routing Service
Cloudflare Worker location headers
The lesson inspects the request information available for geo-routing. Hono wraps the original Request with convenience methods but preserves it under its raw property; the Cloudflare-specific cf object is accessed there. The implementation extracts country, latitude, and longitude so subsequent lessons can use country for routing and coordinates for click analytics.
Primary source: course video 14 · Supplied English subtitles · 00:05:50.
Understand the idea
- Hono’s request wrapper and the underlying incoming Request are related objects with different APIs.
- The raw request exposes Cloudflare-specific metadata under cf, separate from ordinary HTTP request headers.
- Country selects the potential country override; latitude and longitude are intended to enrich click events and later map displays.
- The demonstrated metadata also contains information such as city, timezone, network, region, and an edge location code.
- The cf object and individual values need defensive handling because their availability and inferred types are not assumed by the application.
What the course does
- Inspect Hono’s request context and locate its raw incoming Request.
- Compare inspecting ordinary headers with reading the Cloudflare-specific cf metadata object.
- Review the demonstrated JSON metadata to identify country and coordinate fields.
- Extract country, latitude, and longitude using the optional cf object.
- Return those values from the development route temporarily and inspect the response before adding database-based routing.
Watch for
- The instructor informally calls cf metadata headers; keep the metadata property and ordinary HTTP headers conceptually separate.
- Added advice: the narration mixes edge-server location with request geolocation. Consult current Cloudflare field definitions before interpreting coordinates or colo; the lesson does not establish that they mean the same location.
- Added advice: a country or EU-related flag is not by itself a complete access-control or compliance mechanism.
Recall before revealing
Where does this implementation obtain the country used for routing?
Reveal the explanation
From the Cloudflare-specific cf metadata on Hono’s raw incoming Request, rather than from a country supplied in the short-link URL.
Try it
Inspect a development request and identify its country and coordinate values, including any missing values.
Check your result
You can distinguish Hono’s request wrapper, the raw Request, ordinary headers, and Cloudflare metadata without treating them as interchangeable.
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:01:02 — Access the original raw request
- 00:02:00 — Inspect the Cloudflare cf object
- 00:03:00 — Country and other location metadata
- 00:04:00 — Extract optional routing and coordinate values
Companion primary documentation: Cloudflare Request API. For recorded API names, commands, limits, and prices, check the version you use.