how to use sails.io.js version 0.11.3 in node server

ぐ巨炮叔叔 提交于 2019-11-27 08:40:45

问题


I would like to create a chat application in my sailjs based project, How and where can i configure the socket and related setting in the server ? I got a sample project from this repository but it is using sails v0.10 and i need to use sails v0.11.3, but v0.11.3 having many changes while using socket in Nodejs script, for example, We can't use onConnect since it is deprecated.

I have tried this example, but not working this with sail v0.11.3 https://github.com/sgress454/sailsChat

This is the code i have done, but i don't know where should i put , it is not working when i put this in sockets.js file with in the config directory

// 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:9002';
// ...
    io.socket.on('connect', function socketConnected() {
        console.log('connect..');
    });
// Send a GET request to `http://localhost:1337/hello`:
io.socket.get('/hello', 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);

  // 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)
});

Please guide me on this.


回答1:


Issue has been solved after using the main repository in this link

https://github.com/balderdashy/sailsChat



来源:https://stackoverflow.com/questions/37129766/how-to-use-sails-io-js-version-0-11-3-in-node-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!