This is the forum archive of Homey. For more information about Homey, visit the Official Homey website.
The Homey Community has been moved to https://community.athom.com.
This forum is now read-only for archive purposes.
The Homey Community has been moved to https://community.athom.com.
This forum is now read-only for archive purposes.
Closed
How to get the client's IP address in api.js?
Hi all,
For an app I'm building, I'm exposing an API through Homey, using an api.js file.
So far so good, I've got the basics covered with the direction I want the app to go, and it's working just fine. Based on an API call a flow can be triggered.
However I'd like to identify and authorize the client of the API (i.e. the device that is calling the API through HTTP) by it's IP address.
From what I've found online regarding node.js, a "request" object should be available where a "remoteAddress" property is present. Just what I need.
However, the "fn" property in the module export definition obviously does not contain such a "request" object. Being multi-threaded, a global object for the request should theoretically not exist.
TL;DR: does anyone know of a way to retrieve the client's remote IP address?
For an app I'm building, I'm exposing an API through Homey, using an api.js file.
So far so good, I've got the basics covered with the direction I want the app to go, and it's working just fine. Based on an API call a flow can be triggered.
However I'd like to identify and authorize the client of the API (i.e. the device that is calling the API through HTTP) by it's IP address.
From what I've found online regarding node.js, a "request" object should be available where a "remoteAddress" property is present. Just what I need.
However, the "fn" property in the module export definition obviously does not contain such a "request" object. Being multi-threaded, a global object for the request should theoretically not exist.
TL;DR: does anyone know of a way to retrieve the client's remote IP address?
This discussion has been closed.
Comments
You have available only following args
- params - path params
- body - request body
- query - query string
- files - multipart files
- user - authenticated user
There are also non documented this.req and this.res. This should answer your question, but it's undocumented/unsupported.