sails-permissions
sails-permissions copied to clipboard
Can't get ip address on a sails io socket request.
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.
A PR would be great. I'm not going to have time to look at this until at least next week.
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;
Okay, I will update and check it out. Thank you guy.
Is this resolved by #47?
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
});