Undefined IP on requests
I'm using express and mongo on Deno, and i'm also trying to use express-rate-limit, however, i'm getting the following error on rate-limit because the
request.ip
is undefined:
I've found this answer on a similar question that suggests adding app.set('trust proxy', 1);
i tried it, but the ip continues undefined.19 Replies
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the information you've provided, there are a couple of things to note:
1. The
express-rate-limit
package is designed for use with Express, a web application framework for Node.js, not Deno. Deno has its own set of modules and standard libraries, and it does not natively support Node.js modules without some form of compatibility layer.
2. The error message and stack trace you've provided seem to indicate that you're trying to use Node.js modules (express-slow-down
and express-rate-limit
) within a Deno environment, as evidenced by the file paths containing node_modules
. This is not directly supported by Deno.
3. The app.set('trust proxy', 1);
configuration is specific to Express in a Node.js environment. Deno's standard library and third-party modules for Deno do not recognize this setting.
If you are trying to implement rate limiting in a Deno application, you would need to look for a Deno-specific module or write your own middleware to handle this functionality. You can search for Deno modules on https://deno.land/x or other Deno-related module registries.
Please note that this advice is not based on the Deno documentation, and you should double-check the accuracy of the advice given. If you are working within the Deno runtime, it's important to use Deno-compatible modules and patterns.How to reproduce:
Testing locally i'm able to see my ip on all these variables, while on Deno this is what being printed:
The ip is undefined and its missing all headers, i'm not sure if this is a bug or if i'm missing something, any help is appreciated.
obs: i had to split the question on multiple comments because discord was limiting number of characters
https://github.com/denoland/deno/issues/21980
sad, this already had been reported at 2022 and still didnt fixed
FYI: It turned out to be a bug in the node compat layer. The fix for this will be included in the next Deno release
ty, how do i know when this version is released?
also, will be possible to read the ip as
req.ip
?Releases are published here: https://github.com/denoland/deno/releases
They are usually published in #announcements too
Normally Deno will also check for newer versions automatically and show you a message on the terminal, unless you've disabled it
Yes, but the ip will be on request.ip or will need to look for it somewhere else?
With the bug fix express works as expected and the IP will be accessible on
request.ip
The fact that it wasn't accessible was the bug that the PR fixesi saw that Deno updated to 1.4.0 and the changelog mention your commit
but I continue getting undefined when reading the request ip
Deno Deploy hasn't been updated to Deno 1.4.0 yet
yup, the fix is in CLI, but not on Deno Deploy yet
i thought was the same, where i can follow about the deploy
I don't think that part is communicated publicly. Typically it happens in 1-2 weeks. I've been pushing internally for a while to sync Deno Deploy more timely so that it works the same in Deno Deploy as it does in CLI
hello, do you have any idea if it still will take long to your fixes get in deploy?