Fastify: remoteAddress is undefined in request handler

Created on 5 Mar 2019  路  2Comments  路  Source: fastify/fastify

馃悰 Bug Report

The remoteAddress is undefined if you try to access it with request.ip in a request handler.

To Reproduce

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}`)
})

Expected behavior

The response should contain the remoteAddress. But it is empty.

Your Environment

  • node version: v11.10.1
  • fastify version: 2.0.0
  • os: Windows 10 pro

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 馃槂

All 2 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rabbitooops picture rabbitooops  路  3Comments

lfurzewaddock picture lfurzewaddock  路  3Comments

Jegannathan picture Jegannathan  路  3Comments

moltar picture moltar  路  3Comments

lean picture lean  路  3Comments