Feathers: Accessing remote_address in before hook from REST provider

Created on 5 May 2016  路  5Comments  路  Source: feathersjs/feathers

Hi feathers,

Is it possible to access the remote_address in the before hook and if so, how is it done?

Best regards
Patrick

Most helpful comment

You can add a middleware and set the req.feathers object with that information:

app.use(function(req, res, next) {
  req.feathers.ip = req.ip;
  next();
});

Now it will be available for every REST call in the service parameters as params.ip. For websocket connections you will have to do the same thing in a Socket.io middleware.

All 5 comments

You can add a middleware and set the req.feathers object with that information:

app.use(function(req, res, next) {
  req.feathers.ip = req.ip;
  next();
});

Now it will be available for every REST call in the service parameters as params.ip. For websocket connections you will have to do the same thing in a Socket.io middleware.

Brilliant, thanks!

Glad to help. Closing.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs.

Up to date documentation can be found at: https://docs.feathersjs.com/faq/readme.html#how-do-i-access-the-request-object-in-hooks-or-services

REST example

https://docs.feathersjs.com/api/express.html#params

Web Sockets example

https://docs.feathersjs.com/api/socketio.html#appconfiguresocketiocallback

Was this page helpful?
0 / 5 - 0 ratings

Related issues

corymsmith picture corymsmith  路  4Comments

eric-burel picture eric-burel  路  3Comments

arkenstan picture arkenstan  路  3Comments

codeus-de picture codeus-de  路  4Comments

arve0 picture arve0  路  4Comments