Closed
Description
Environment
[2:31:36 PM] Nuxt project info:
- Operating System: Windows_NT
- Node Version: v18.13.0
- Nuxt Version: 3.9.1
- CLI Version: 3.10.0
- Nitro Version: 2.8.1
- Package Manager: [email protected]
- Builder: -
- User Config: devtools
- Runtime Modules: -
- Build Modules: -
Reproduction
Nuxt project with a middleware and a plugin, both failing to get a client IP:
https://github.com/xtance/nuxt-app-ip/
As compared to the blank h3 app:
https://github.com/xtance/h3-app-ip
Describe the bug
I'm trying to get client IP address from an event and it couldn't show it. The only way is to read x-forwarded-for
header and there it's always 127.0.0.1
export default defineNuxtRouteMiddleware((to, from) => {
const nuxt = useNuxtApp();
const event = useRequestEvent(nuxt);
console.log(
'IP',
event.context.clientAddress,
event.node.req.connection.remoteAddress,
event.node.req.socket.remoteAddress,
getRequestIP(event),
getRequestIP(event, { xForwardedFor: true }),
);
})
It returns "IP undefined undefined undefined undefined 127.0.0.1" (I also tried with a server plugin in /plugins/server)
Since I read that nuxt uses h3 I created a blank project to test it and it shows my real IP. (See in reproduction section)
Additional context
I was wondering if I'm alone with this issue but here is a discussion: nuxt/nuxt#25059
Logs
No response