Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR TypeError: Cannot read property 'remoteAddress' of undefined #24

Open
medisoft opened this issue Dec 6, 2018 · 3 comments
Open

Comments

@medisoft
Copy link

medisoft commented Dec 6, 2018

Hello. I'm testing this module to be able to have single api called by socket and by http, but I'm getting this error:

ERROR TypeError: Cannot read property 'remoteAddress' of undefined at forwarded (/Users/osoverflow/IdeaProjects/domitai/dokku/node_modules/forwarded/index.js:31:35) at alladdrs (/Users/osoverflow/IdeaProjects/domitai/dokku/node_modules/proxy-addr/index.js:57:15) at proxyaddr (/Users/osoverflow/IdeaProjects/domitai/dokku/node_modules/proxy-addr/index.js:231:15) at IncomingMessage.ip (/Users/osoverflow/IdeaProjects/domitai/dokku/node_modules/express/lib/request.js:351:10) at getip (/Users/osoverflow/IdeaProjects/domitai/dokku/node_modules/morgan/index.js:466:14) at logger (/Users/osoverflow/IdeaProjects/domitai/dokku/node_modules/morgan/index.js:107:26) at Layer.handle [as handle_request] (/Users/osoverflow/IdeaProjects/domitai/dokku/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/Users/osoverflow/IdeaProjects/domitai/dokku/node_modules/express/lib/router/index.js:317:13) at /Users/osoverflow/IdeaProjects/domitai/dokku/node_modules/express/lib/router/index.js:284:7 at Function.process_params (/Users/osoverflow/IdeaProjects/domitai/dokku/node_modules/express/lib/router/index.js:335:12) at next (/Users/osoverflow/IdeaProjects/domitai/dokku/node_modules/express/lib/router/index.js:275:10) at app.use (/Users/osoverflow/IdeaProjects/domitai/dokku/node_modules/run-middleware/index.js:16:5) at Layer.handle [as handle_request] (/Users/osoverflow/IdeaProjects/domitai/dokku/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/Users/osoverflow/IdeaProjects/domitai/dokku/node_modules/express/lib/router/index.js:317:13) at /Users/osoverflow/IdeaProjects/domitai/dokku/node_modules/express/lib/router/index.js:284:7 at Function.process_params (/Users/osoverflow/IdeaProjects/domitai/dokku/node_modules/express/lib/router/index.js:335:12) +6ms 500 '<h1>Cannot read property &#39;remoteAddress&#39; of undefined</h1>\n<h2></h2>\n<pre></pre>\n' { 'X-Powered-By': 'Express', 'x-powered-by': 'Express' }

@kingzevin
Copy link

I encountered the same problem.
Could you please tell me if you solved it?

@laekem34
Copy link

laekem34 commented May 30, 2020

Hello,

I thinks it's because (if you take a look at the index.js of the module, function createRes), the Response object "emulated" by app.runMiddleware doesn't have a res.connection property. So if somewhere in a middleware crossed by the path given, you use req.connection.remoteAdress, connection will be undefined and that will cause this error.

If i'm not mistaken, try to run the same path inside a request middleware with req.runMiddleware. In this case, the req and res normal object will be used, and you shouldn't have this error because req.connection exists.

To solve your problem, you can try to add connection property manually in the options argument
app.runMiddleware('path/to/your/request', { connection: { remoteAddress: /fakeAdress/ } }, /callback/)

@Aminadav
Copy link
Owner

If you wish the create a fix, I will review and merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants