pbojinov / request-ip

A Node.js module for retrieving a request's IP address on the server.
https://npmjs.com/package/request-ip
MIT License
828 stars 102 forks source link

Does it support AdonisJS? #58

Closed sooluh closed 2 years ago

sooluh commented 2 years ago

Hello, I have a question, and my suggestion, maybe the owner should enable the Discussion feature in this repository for questions like this, thanks.

pbojinov commented 2 years ago

Hi @sooluh that's a great suggestion for discussions. I've enabled it here https://github.com/pbojinov/request-ip/discussions

As far as AdonisJS, I haven't personally tested used this web framework but I assume it should work as long as it supports one of the methods described here – https://github.com/pbojinov/request-ip#how-it-works

sooluh commented 2 years ago

Hi @pbojinov, thanks for the response.

About this question, I've tried it in AdonisJS, and yes it works, but it's not enough to pass the request argument from AdonisJS to the getClientIp() method.

Because in AdonisJS, the http context received from the request object is a method-based object, so we have to change it first to JSON, fortunately in AdonisJS itself has a toJSON() method in the request object, so at least it's easier.

We need to pass request.toJSON() to the getClientIp() method, because after I review the code of this module, it uses request.headers (not a method), but in AdonisJS to get headers, we need to use request.headers() method, or for values from the header specifically, we use request.header('key').

Thanks, I will close this issue.