sails-permissions icon indicating copy to clipboard operation
sails-permissions copied to clipboard

Can't get ip address on a sails io socket request.

Open hankphung opened this issue 9 years ago • 5 comments

I got those error when use sails socket.io js. code: error: Sending 500 ("Server Error") response: TypeError: Cannot read property 'remoteAddress' of undefined at module.exports (/Users/chipgata/Projects/Backend-Tracking-Marketing/node_modules/sails-permissions/api/policies/AuditPolicy.js:6:67)

error: Sending 500 ("Server Error") response: TypeError: undefined is not a function at sanitizeRequestUrl (/Users/chipgata/Projects/Backend-Tracking-Marketing/node_modules/sails-permissions/api/policies/AuditPolicy.js:29:15)

Problem is this connection really don't have ip attribute in req object. But ip come alone with socket object that included in req object. Hope you have a fix for this soon. Thank you.

hankphung avatar Apr 26 '15 06:04 hankphung

A PR would be great. I'm not going to have time to look at this until at least next week.

tjwebb avatar Apr 28 '15 06:04 tjwebb

This fixes the IP issue, at least it's in the right direction.

var ipAddress = req.isSocket ? req.socket.handshake.address.address + ":" + req.socket.handshake.address.port : req.headers['x-forwarded-for'] || req.connection.remoteAddress;

scott-wyatt avatar May 11 '15 17:05 scott-wyatt

Okay, I will update and check it out. Thank you guy.

hankphung avatar May 29 '15 06:05 hankphung

Is this resolved by #47?

tjwebb avatar Jun 10 '15 01:06 tjwebb

Hey team, after update current Sails-Permission version, I no-longer get Ipaddress error. But get this error when try to get collection by sails's io.socket GET method.

error: Sending 500 ("Server Error") response: 
 TypeError: Object #<MockIncomingMessage> has no method 'get'
    at sanitizeRequestUrl (/home/hank/git/node/*****/node_modules/sails-permissions/api/policies/AuditPolicy.js:26:15)

This is line 24 to 28 of AuditPolicy.

 var requestUrl = url.format({
    protocol: req.protocol,
    host: req.get('host'),
    pathname: req.originalUrl,
    query: req.query
  });

hankphung avatar Jun 11 '15 14:06 hankphung