local-dev mode runs the gateway on your machine with routes and
policies from a TOML file. This example puts it in front of traefik/whoami, an
HTTP echo service that returns request headers. No application code is needed.
A valid API key reaches the echo service with an
X-Unkey-Principal header. Frontline
rejects missing or invalid keys before they reach the service. To test your
application’s header handling without real key verification, you can
mock a Principal instead.
Prerequisites
You need Docker Compose, a keyspace, a root key with permission to verify keys in that keyspace, and an API key from that keyspace.The Frontline prerelease in this example requires an Unkey API that accepts
the
keyspaces verification parameter and returns keyspaceId for valid keys.
An older API rejects that parameter with HTTP 400, which Frontline reports as
HTTP 500. Releasing Frontline alone does not update the verification API.
Set UNKEY_API_URL to a compatible API if those changes are not deployed to
the hosted API.Configure the containers
Create these three files in the same directory. Replace the root key and keyspace ID in.env with your development values.
localhost refers to
that container, not your host. Use a container-reachable URL if you run your own
verification API.
The policy sets credits = 0 to avoid deducting key credits. Verification still
uses the real Unkey API, so key expiration and key rate limits still apply.
Start the gateway
Run these commands from the directory containing the three files:Inspect the forwarded headers
Set your API key in the terminal, then send a request through Frontline:X-Unkey-Principal, X-Forwarded-Host, and
X-Forwarded-Proto: http. Header capitalization can differ. The principal’s
subject is the key’s identity external ID, or its key ID if it has no identity.
Send the same request without a key to check rejection:
Use named hosts
Theapi.test network alias belongs to Frontline, not the echo service.
Containers on this Compose network can call http://api.test:8080.
Frontline resolves its upstream separately as api:80.
Compose aliases do not configure your host’s DNS. The curl commands use
--resolve so no hosts-file change is needed. For a browser on your host, add
127.0.0.1 api.test to your hosts file. For additional hostnames, add both a
Frontline route and a network alias. Add host DNS entries separately when needed.
To use your own application, replace the api service and set upstream to its
Compose service name and listening port. Keep its port internal so requests
cannot bypass Frontline.