From 4122da17b948c528e5c2887b986a35d09ec2e8e7 Mon Sep 17 00:00:00 2001 From: Delba de Oliveira Date: Fri, 13 Sep 2024 11:28:03 +0100 Subject: [PATCH] Remove IP address example - See https://github.com/vercel/next.js/pull/68379 - Additionally, people can read the headers available in their system, we don't have to document them individually in the API for accessing them. --- .../02-api-reference/04-functions/headers.mdx | 37 +------------------ 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/docs/02-app/02-api-reference/04-functions/headers.mdx b/docs/02-app/02-api-reference/04-functions/headers.mdx index 885d6935e03bc..f429ec947062d 100644 --- a/docs/02-app/02-api-reference/04-functions/headers.mdx +++ b/docs/02-app/02-api-reference/04-functions/headers.mdx @@ -53,7 +53,7 @@ export default async function Page() { ### Using the Authorization header -````jsx filename="app/page.js" +```jsx filename="app/page.js" import { headers } from 'next/headers' export default async function Page() { @@ -65,40 +65,7 @@ export default async function Page() { return

{user.name}

} -#### IP Address - -`headers()` can be used to get the IP address of the client. - -```jsx filename="app/page.js" -import { Suspense } from 'react' -import { headers } from 'next/headers' - -function IP() { - const FALLBACK_IP_ADDRESS = '0.0.0.0' - const forwardedFor = headers().get('x-forwarded-for') - - if (forwardedFor) { - return forwardedFor.split(',')[0] ?? FALLBACK_IP_ADDRESS - } - - return headers().get('x-real-ip') ?? FALLBACK_IP_ADDRESS -} - -export default function Page() { - return ( - - - - ) -} -```` - -In addition to `x-forwarded-for`, `headers()` can also read: - -- `x-real-ip` -- `x-forwarded-host` -- `x-forwarded-port` -- `x-forwarded-proto` +``` ## Version History