Skip to content

Conversation

@rokasta12
Copy link

Summary

This PR adds getConnInfo() support to three adapters that were previously missing this functionality:

  • AWS Lambda - Supports API Gateway v1, v2, and ALB
  • Cloudflare Pages - Uses cf-connecting-ip header (same as Workers)
  • Netlify - Uses context.ip + bonus getGeo() helper

Changes

AWS Lambda (hono/aws-lambda)

  • Extracts client IP from requestContext.identity.sourceIp (API Gateway v1)
  • Extracts client IP from requestContext.http.sourceIp (API Gateway v2 / Function URLs)
  • Falls back to x-forwarded-for header (ALB)

Cloudflare Pages (hono/cloudflare-pages)

  • Uses cf-connecting-ip header (identical to Cloudflare Workers)

Netlify (hono/netlify)

  • Uses context.ip for client IP
  • Adds getGeo() helper for geolocation data (city, country, subdivision, timezone, postalCode, etc.)

Usage Examples

// AWS Lambda
import { Hono } from 'hono'
import { handle, getConnInfo } from 'hono/aws-lambda'

const app = new Hono()
app.get('/', (c) => {
  const info = getConnInfo(c)
  return c.text(`Your IP: ${info.remote.address}`)
})
export const handler = handle(app)

// Cloudflare Pages
import { handle, getConnInfo } from 'hono/cloudflare-pages'
// ... same pattern

// Netlify (with geo)
import { handle, getConnInfo, getGeo } from 'hono/netlify'
app.get('/', (c) => {
  const info = getConnInfo(c)
  const geo = getGeo(c)
  return c.json({ ip: info.remote.address, country: geo?.country?.code })
})

References

Checklist

  • Tests added (12 tests, 100% coverage on new files)
  • Follows existing patterns (matches cloudflare-workers, vercel, lambda-edge, etc.)
  • TypeScript types included
  • JSDoc with examples

@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.43%. Comparing base (bcc81b1) to head (9891da1).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4649      +/-   ##
==========================================
- Coverage   91.45%   91.43%   -0.02%     
==========================================
  Files         173      176       +3     
  Lines       11322    11362      +40     
  Branches     3279     3290      +11     
==========================================
+ Hits        10354    10389      +35     
- Misses        967      972       +5     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yusukebe yusukebe added the v4.12 label Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants