Created
February 19, 2026 23:31
-
-
Save codigoconjuan/dab91f1729e071e6afd648de0a412d44 to your computer and use it in GitHub Desktop.
Identificar IP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { headers } from "next/headers"; | |
| export async function getClientIp(): Promise<string> { | |
| const headersList = await headers(); | |
| return ( | |
| headersList.get("cf-connecting-ip") || // Cloudflare | |
| headersList.get("x-vercel-forwarded-for") || // Vercel | |
| headersList.get("x-real-ip") || // Nginx / proxies | |
| headersList.get("x-forwarded-for")?.split(",")[0].trim() || // standard | |
| headersList.get("remote-addr") || // fallback local/dev | |
| "unknown" | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment