feat: fix resourceUrl when hono server is behind reverse proxy
Fix: Hono middleware now correctly handles reverse proxy environments
Problem
When the Hono middleware was deployed behind reverse proxies (Vercel, Railway, etc.), the resource URL in payment requirements would incorrectly use http:// instead of https://, causing discovery failures. This occurred because Hono servers behind reverse proxies operate in an HTTP context, and unlike Express or Next.js, Hono doesn't automatically handle reverse proxy environments.
Root Cause
The middleware was directly using c.req.url to construct the resource URL. In reverse proxy environments, this URL reflects the internal HTTP connection between the proxy and the server, not the external HTTPS connection from the client to the proxy. The reverse proxy sets X-Forwarded-Proto and X-Forwarded-Host headers to indicate the original protocol and host, but the middleware wasn't checking for these headers.
Related Hono issue: https://github.com/honojs/node-server/issues/146
Solution
The middleware now:
- Checks for
X-Forwarded-ProtoandX-Forwarded-Hostheaders when no customresourceis configured - Reconstructs the resource URL using these forwarded headers if present, ensuring the correct protocol (https) and host
- Falls back to the original behavior (
c.req.url) when not behind a reverse proxy
Checklist
- [x] I have formatted and linted my code
- [x] All new and existing tests pass
- [x] My commits are signed (required for merge) -- you may need to rebase if you initially pushed unsigned commits
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| x402 | Preview | Comment | Nov 12, 2025 11:42pm |
✅ Heimdall Review Status
| Requirement | Status | More Info | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Reviews |
✅
1/1
|
Denominator calculation
|