Next.js Discord

Discord Forum

"x-forwarded-for" is not included anymore on the headers array while on dev mode

Unanswered
Barbary Lion posted this in #help-forum
Open in Discord
Barbary LionOP
I've noticed that after upgrading from "13.4.12" version to the latest (13.5.2) and while on dev mode localhost theres not anymore "x-forwarded-for" included on the headers array returned by

import { headers } from "next/headers";
const headersList = headers();

like on the previous mentioned version where it was returning a value of "::1"
pushing it on vercel works like a charm, but still worries me why this stopped working, i've tried to track down any related change that could lead to this, but sadly nothing mentioned got my attention

13 Replies

only thing i can find is:
On NextRequest, geo and ip are empty/undefined unless provided by the hosting platform as documented here:
https://github.com/vercel/next.js/issues/47793#issuecomment-1493227349
Barbary LionOP
yeah i've seen that, but still on "13.4.12" version and while on dev mode (localhost) i am getting a defined value of "::1"
which is not the case after upgrading to the latest
so it like something has changed somehow
it's documented that the value can be unavailable, so it might change without notice and you have to handle the case where it's not available
it's a common practice that you fallback to a default value
Barbary LionOP
oh well i get that, i just wanted to know if anyone from the team had more information regarding it, any advice on what would be the best scenario of handling that case of undefined?
i've seen solutions where you GET IP and geo data on middleware with a fetch on external API
Barbary LionOP
got it, i am building an app where users can perform votes and basically IP for me is "one" of the measures to check the validity of the vote ( in combination with other factors ) so i will have to think of something more reliable if for any reason the IP is undefined as a fallback scenario, but will figure out something, maybe if IP is undefined ( which should not while hosting on vercel ) i will permit voting.

one last questions, middleware will handle the issue for page.tsx but what about API routes?
not sure if middleware effects requests on API routes as-well
Middleware is run for both page files and route handlers
Barbary LionOP
thank you