好的,所以套接字连接和一切。我可以调试控制器,但当它到达行返回res.ok()时它会中断。我也有一个res.json({message:" hello"})。但我得到同样的错误。
/*** SocketController
*
* @description :: Server-side logic for managing Sockets
* @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers
*/
module.exports = {
AddFolder: function(req, res) {
// a socket request
if (req.isSocket) {
sails.log("Test");
return res.ok();
} else {
return res.badRequest();
}
}
};
这就是我所说的。
var socketIOClient = require('socket.io-client');
var sailsIOClient = require('sails.io.js');
// Instantiate the socket client (`io`)
// (for now, you must explicitly pass in the socket.io client when using this library from Node.js)
var io = sailsIOClient(socketIOClient);
// Set some options:
// (you have to specify the host and port of the Sails backend when using this library from Node.js)
io.sails.url = 'http://localhost:1337';
io.socket.get('/Socket/AddFolder', function serverResponded (body, JWR) {
// body === JWR.body
console.log('Sails responded with: ', body);
console.log('with headers: ', JWR.headers);
console.log('and with status code: ', JWR.statusCode);
// ...
// more stuff
// ...
// When you are finished with `io.socket`, or any other sockets you connect manually,
// you should make sure and disconnect them, e.g.:
io.socket.disconnect();
// (note that there is no callback argument to the `.disconnect` method)
});
我得到的错误是:
TypeError: Right-hand side of 'instanceof' is not callable
index.js:31
at _hasBinary (d:\Test\TestProject\backend\node_modules\has-binary\index.js:31:30)
at hasBinary (d:\Test\TestProject\backend\node_modules\has-binary\index.js:58:10)
at Object.socketIOClientCallback (d:\Test\TestProject\backend\node_modules\socket.io\lib\socket.js:369:16)
at MockServerResponse._clientCallback (d:\Test\TestProject\backend\node_modules\sails-hook-sockets\lib\receive-incoming-sails-io-msg.js:219:17)
at MockClientResponse.<anonymous> (d:\Test\TestProject\backend\node_modules\sails\lib\router\res.js:59:18)
at MockClientResponse.emit (events.js:164:20)
at finishMaybe (_stream_writable.js:616:14)
at endWritable (_stream_writable.js:624:3)
at MockClientResponse.Writable.end (_stream_writable.js:575:5)
at MockServerResponse.onend (_stream_readable.js:598:10)
at Object.onceWrapper (events.js:254:19)
at MockServerResponse.emit (events.js:164:20)
at endReadableNT (_stream_readable.js:1062:12)
at process._tickCallback (internal/process/next_tick.js:152:19)
有人可以帮忙吗?我不知道为什么会失败。
提前谢谢。
答案 0 :(得分:2)
好的,我发现了问题所在。如果您的模型名为File.js,则会发生此错误。