The remoteAddress is undefined if you try to access it with request.ip in a request handler.
Steps to reproduce the behavior:
Run the example code and make a get request to http://localhost:8080
// Require the framework and instantiate it
const fastify = require('fastify')({logger: true})
// Declare a route
fastify.get('/', (request, reply) => {
reply.send({remoteAddress: request.ip})
})
// Run the server!
fastify.listen(8080, '0.0.0.0', (err) => {
if (err) {
fastify.log.error(err)
process.exit(1)
}
fastify.log.info(`server listening on ${fastify.server.address().port}`)
})
The response should contain the remoteAddress. But it is empty.
Hi,
in fastify v2.0.0 there is not the field request.ip.
You can get that info by reply.send({ remoteAddress: request.raw.connection.remoteAddress })
Anyway, there is a working PR https://github.com/fastify/fastify/pull/1476 that will add that information exactly in request.ip.. so stay in touch for the next version of fastify v2 馃槂
Ah shame on me, I've only looked into request.raw.headers/rawHeaders but not request.raw.connection. Thank you!
Most helpful comment
Hi,
in fastify v2.0.0 there is not the field
request.ip.You can get that info by
reply.send({ remoteAddress: request.raw.connection.remoteAddress })Anyway, there is a working PR https://github.com/fastify/fastify/pull/1476 that will add that information exactly in
request.ip.. so stay in touch for the next version of fastify v2 馃槂