So I am running Sailsv0.10 and I have a fairly simple blueprint override for create in my WorkoutController.
create: function(req, res) {
var workout = req.params.all();
workout.user = req.user.id;
sails.log.verbose(workout)
Workout.create(workout).exec(function(err, workout) {
// Error handling
if (err) return res.negotiate(err);
res.send(201);
res.ok(workout.toJSON());
});
},
The models looks like this
Workout.js ->
module.exports = {
attributes: {
/* e.g.
nickname: 'string'
*/
date : "date",
input: {
type: 'string',
enum: ['auto','manual']
},
tss : "float",
user: {
model: 'user'
}
}
};
When I send a http POST to /workout everything works as expected however when I send it through a socket using the sails io socket client I get the following
verbose: Routing message over socket: { method: 'post',
data: { tss: 0, date: '2014-07-07T14:00:00.000Z', input: 'manual' },
url: '/workout',
headers: {} }
verbose: sending data ack packet
verbose: websocket writing 6:::2+[{"body":{},"headers":{},"statusCode":500}]
I am not sure if the status code 500 is related but there is no other bits of helpful information.
To try and locate the problem I have also tried
Update, so it seems the problem has to do with the policies
WorkoutController : {
"*" : "isBasicPassportAuthenticated"
},
isBasicPassportAuthenticated
// Credit:
// @theangryangel https://gist.github.com/theangryangel/5060446
// @Mantish https://gist.github.com/Mantish/6366642
// @anhnt https://gist.github.com/anhnt/8297229
var passport = require('passport');
// We use passport to determine if we're authenticated
module.exports = function(req, res, next) {
if (req.isAuthenticated())
return next();
passport.authenticate(['basic','local'], function(err, user, info) {
if (err) return next(err);
if (!user) {
return res.forbidden('You are not permitted to perform this action.');
}
req.logIn(user, function(err) {
if (err) return next(err);
next();
});
})(req, res, next);
};
Everything looks fine, so I am still not sure what is going on