D
Deno

help

Undefined IP on requests

LLaslo1/16/2024
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:
ValidationError: An undefined 'request.ip' was detected. This might indicate a misconfiguration or the connection being destroyed prematurely. See https://express-rate-limit.github.io/ERR_ERL_UNDEFINED_IP_ADDRESS/ for more information.
at Object.ip (file:///node_modules/.deno/express-rate-limit@7.1.5/node_modules/express-rate-limit/dist/index.mjs:97:13)
at Object.wrappedValidations.<computed> [as ip] (file:///node_modules/.deno/express-rate-limit@7.1.5/node_modules/express-rate-limit/dist/index.mjs:296:22)
at Object.keyGenerator (file:///node_modules/.deno/express-rate-limit@7.1.5/node_modules/express-rate-limit/dist/index.mjs:549:20)
at file:///node_modules/.deno/express-rate-limit@7.1.5/node_modules/express-rate-limit/dist/index.mjs:601:32
at Object.runMicrotasks (ext:core/01_core.js:934:26)
at processTicksAndRejections (ext:deno_node/_next_tick.ts:53:10)
at runNextTicks (ext:deno_node/_next_tick.ts:71:3)
at eventLoopTick (ext:core/01_core.js:189:21)
at async file:///node_modules/.deno/express-rate-limit@7.1.5/node_modules/express-rate-limit/dist/index.mjs:583:5 {
name: "ValidationError",
code: "ERR_ERL_UNDEFINED_IP_ADDRESS",
help: "https://express-rate-limit.github.io/ERR_ERL_UNDEFINED_IP_ADDRESS/"
}
ValidationError: An undefined 'request.ip' was detected. This might indicate a misconfiguration or the connection being destroyed prematurely. See https://express-rate-limit.github.io/ERR_ERL_UNDEFINED_IP_ADDRESS/ for more information.
at Object.ip (file:///node_modules/.deno/express-rate-limit@7.1.5/node_modules/express-rate-limit/dist/index.mjs:97:13)
at Object.wrappedValidations.<computed> [as ip] (file:///node_modules/.deno/express-rate-limit@7.1.5/node_modules/express-rate-limit/dist/index.mjs:296:22)
at Object.keyGenerator (file:///node_modules/.deno/express-rate-limit@7.1.5/node_modules/express-rate-limit/dist/index.mjs:549:20)
at file:///node_modules/.deno/express-rate-limit@7.1.5/node_modules/express-rate-limit/dist/index.mjs:601:32
at Object.runMicrotasks (ext:core/01_core.js:934:26)
at processTicksAndRejections (ext:deno_node/_next_tick.ts:53:10)
at runNextTicks (ext:deno_node/_next_tick.ts:71:3)
at eventLoopTick (ext:core/01_core.js:189:21)
at async file:///node_modules/.deno/express-rate-limit@7.1.5/node_modules/express-rate-limit/dist/index.mjs:583:5 {
name: "ValidationError",
code: "ERR_ERL_UNDEFINED_IP_ADDRESS",
help: "https://express-rate-limit.github.io/ERR_ERL_UNDEFINED_IP_ADDRESS/"
}
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.
DAHDeno AI Helper1/16/2024
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.
LLaslo1/18/2024
How to reproduce:
"use strict"

import express from 'express';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import rateLimit from 'express-rate-limit';

const app = express();

mongoose.connect("...");
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() { console.log('Connected to MongoDB'); });

app.use(bodyParser.json());
app.set('trust proxy', 1);

const limiter = rateLimit({ windowMs: 1 * 60 * 1000, max: 3, });
app.post('/api/users', limiter, async (req, res) =>
{
console.log('ip:', req.ip);
console.log('conn:', req.connection)
console.log('conn.remoteAddress:', req.connection.remoteAddress)
console.log('client:', req.client);
console.log('headers:', req.headers);
console.log('rawHeaders:', req.rawHeaders);
console.log('X-Forwarded-For:', req.headers['x-forwarded-for']);
console.dir('req:', req);
try {
const variable = await db.collection("users").findOne({ [req.body.user]: { $exists: true } })
if (!variable) return res.status(404).send('Not found');
res.send(variable);
}
catch (error) { res.status(500).send('Internal Server Error'); }
});

app.listen(5000, () => { console.log(`running`); });
"use strict"

import express from 'express';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import rateLimit from 'express-rate-limit';

const app = express();

mongoose.connect("...");
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() { console.log('Connected to MongoDB'); });

app.use(bodyParser.json());
app.set('trust proxy', 1);

const limiter = rateLimit({ windowMs: 1 * 60 * 1000, max: 3, });
app.post('/api/users', limiter, async (req, res) =>
{
console.log('ip:', req.ip);
console.log('conn:', req.connection)
console.log('conn.remoteAddress:', req.connection.remoteAddress)
console.log('client:', req.client);
console.log('headers:', req.headers);
console.log('rawHeaders:', req.rawHeaders);
console.log('X-Forwarded-For:', req.headers['x-forwarded-for']);
console.dir('req:', req);
try {
const variable = await db.collection("users").findOne({ [req.body.user]: { $exists: true } })
if (!variable) return res.status(404).send('Not found');
res.send(variable);
}
catch (error) { res.status(500).send('Internal Server Error'); }
});

app.listen(5000, () => { console.log(`running`); });
Testing locally i'm able to see my ip on all these variables, while on Deno this is what being printed:
ip: undefined
conn: FakeSocket {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
remoteAddress: undefined,
remotePort: undefined,
encrypted: undefined,
writable: true,
readable: true,
[Symbol(kCapture)]: false
}
conn.remoteAddress: undefined
client: undefined
headers:
{
"accept-encoding": "gzip, deflate",
"accept-language": "en-US,en,*",
"content-length": "14",
"content-type": "application/json",
host: "....deno.dev",
"user-agent": "Mozilla/5.0"
}
rawHeaders: undefined
client: undefined
X-Forwarded-For: undefined
req: <ref *1> IncomingMessageForServer {
_readableState: ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: [],
flowing: true,
ended: true,
endEmitted: true,
reading: false,
constructed: true,
sync: false,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
destroyed: true,
errored: null,
closed: true,
closeEmitted: false,
defaultEncoding: "utf8",
awaitDrainWriters: null,
multiAwaitDrain: false,
readingMore: false,
dataEmitted: true,
decoder: null,
encoding: null,
[Symbol(kPaused)]: false
},
_read: [AsyncFunction: read],
_destroy: [Function: destroy],
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
url: "/api/users",
method: "POST",
next: [Function: next],
baseUrl: "",
originalUrl: "/api/users",
_parsedUrl: Url {
protocol: null,
slashes: null,
auth: null,
host: null,
port: null,
hostname: null,
hash: null
ip: undefined
conn: FakeSocket {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
remoteAddress: undefined,
remotePort: undefined,
encrypted: undefined,
writable: true,
readable: true,
[Symbol(kCapture)]: false
}
conn.remoteAddress: undefined
client: undefined
headers:
{
"accept-encoding": "gzip, deflate",
"accept-language": "en-US,en,*",
"content-length": "14",
"content-type": "application/json",
host: "....deno.dev",
"user-agent": "Mozilla/5.0"
}
rawHeaders: undefined
client: undefined
X-Forwarded-For: undefined
req: <ref *1> IncomingMessageForServer {
_readableState: ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: [],
flowing: true,
ended: true,
endEmitted: true,
reading: false,
constructed: true,
sync: false,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
destroyed: true,
errored: null,
closed: true,
closeEmitted: false,
defaultEncoding: "utf8",
awaitDrainWriters: null,
multiAwaitDrain: false,
readingMore: false,
dataEmitted: true,
decoder: null,
encoding: null,
[Symbol(kPaused)]: false
},
_read: [AsyncFunction: read],
_destroy: [Function: destroy],
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
url: "/api/users",
method: "POST",
next: [Function: next],
baseUrl: "",
originalUrl: "/api/users",
_parsedUrl: Url {
protocol: null,
slashes: null,
auth: null,
host: null,
port: null,
hostname: null,
hash: null
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
Mmarvinh.1/19/2024
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
LLaslo1/19/2024
ty, how do i know when this version is released? also, will be possible to read the ip as req.ip?
LLeokuma1/20/2024
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
LLaslo1/20/2024
Yes, but the ip will be on request.ip or will need to look for it somewhere else?
Mmarvinh.1/20/2024
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 fixes
LLaslo1/25/2024
No description
LLaslo1/25/2024
i saw that Deno updated to 1.4.0 and the changelog mention your commit but I continue getting undefined when reading the request ip
Mmarvinh.1/25/2024
Deno Deploy hasn't been updated to Deno 1.4.0 yet
LLaslo1/25/2024
No description
Mmarvinh.1/25/2024
yup, the fix is in CLI, but not on Deno Deploy yet
LLaslo1/25/2024
i thought was the same, where i can follow about the deploy
Mmarvinh.1/25/2024
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
LLaslo2/1/2024
hello, do you have any idea if it still will take long to your fixes get in deploy?
Mmarvinh.2/1/2024
My understanding is that the fix is already available in Deploy. Do you still see the error?
LLaslo2/1/2024
No description
LLaslo2/12/2024
? :samurai_deno: šŸ‘Ž
Mmarvinh.2/12/2024
If it still errors then it looks like it's not updated on Deploy yet. We're currently in the middle of restructuring the relationship between CLI and Deno Deploy to ensure that they are more in sync and that bug fixes in the CLI are available on Deploy in a timely manner. This is work that's more difficult than anticipated and I don't have a timeline when the fix will be available.

Looking for more? Join the community!

Recommended Posts
How to use `f-partial` from Fresh?Show me an example of using `f-partial` in a Deno Fresh project.KV watch initial valueDoes KV watch always trigger an initial read of the current value? Is there a way to only watch forThe deployment failed: Relative import path "$fresh/server.ts" not prefixed with / or ./ or ../When deploying I get this error: ``` Deploying... (100.0%) Error: The deployment failed: Relative imDeno Deploy: Timeout PageIs there a way to replace the standard deno deploy timeout error page? I have a use case where I allFresh, deno deploy microservices and authHi, I want to design a Fresh frontend and api working with deno microservices and auth. My proposalEventSource vs Multiplex webookI am setting up an system that needs realtime updates for potentially 100+ different resources on a rusty_v8 - how to pass data from js/v8 into rustHello, I am playing with rusty_v8, by following the examples I was able to get js eval up and runninDeno deploy - My simple mail service is giving a connection error (works fine locally or on vercel)As the title states my small email sending API is not working on deno deploy. Maybe there needs to bHow to send data from a child component to its sibling?I want create an app with two forms, each form in its own component. Users type in form 1, then the Can Deno list all functions within a script without explicit registration or annotation?. ## For context, here is how you do it for `globalThis`: ```ts Object.getOwnPropertyNames(globalThiTypescript intelisense between jupyter notebooksI've been trying to run jupyter notebooks with deno, but I've noticed that if I create a variable inhow to compress string into stringHow would i go about compressing a string? i need to compress a string but i need the compressed valFresh - Page title to LayoutHi, I have been browsing around the docs and also being new to JSX,I'm not sure what I look for. WhaWhen I use deno run I get this error: error : Permission denied (os error 13)When I use deno run I get this error: error : Permission denied (os error 13) (for '/Users/apple/LibAxios HttpsProxyAgentHello, I tryed to search but found nothing. I'm using axios with httpProxyAgent to proxy my outgoingGet input from an island, make calculus then render ?I have a route with 2 islands inside - one to get input from user - one to render data Once I've goHow can I create a seqential deno task to pass args to child task?Hi, I read the docs and created tasks in `deno.json` like this. https://docs.deno.com/runtime/manualUsing SCSS with FreshHi, I'm starting to get into Fresh for building simple static websites. Right now I want to use my Has anyone used React Material UI with Deno Fresh? Is this possible and also what are the componenetHas anyone used React Material UI with Deno Fresh? Is this possible and also what are the componenetJSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements'I have a core program, and from that I have auxiliary components: test, web app, cli app. Initially