所以我正在运行Sailsv0.10,我在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());
});
},
模型看起来像这样
Workout.js - >
module.exports = {
attributes: {
/* e.g.
nickname: 'string'
*/
date : "date",
input: {
type: 'string',
enum: ['auto','manual']
},
tss : "float",
user: {
model: 'user'
}
}
};
当我发送http POST到/ workout时,一切都按预期工作,但是当我使用sails io套接字客户端通过套接字发送它时,我得到以下内容
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}]
我不确定状态代码500是否相关,但没有其他有用的信息。
尝试找到我也尝试过的问题
更新,因此问题似乎与政策
有关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);
};
一切都很好,所以我仍然不确定发生了什么