@ feathersjs / socketio-client连接超时。为什么?

时间:2018-01-04 11:09:58

标签: feathersjs

我跟着说:

 feathers g app # with socket and rest
 feathers g service # todos & NeDB
 npm start

和简单的客户端。我从文档中复制代码 https://docs.feathersjs.com/api/client/socketio

 const feathers = require('@feathersjs/feathers');
 const socketio = require('@feathersjs/socketio-client');
 const io = require('socket.io-client');

 const socket = io('http://localhost:3030');
 const app = feathers();

 app.configure(socketio(socket));


 app.service('todos')
   .on('created', message => console.log('New message created', message));

 app.service('todos').find().then(r => {
    console.log(r)
 }).catch(e => console.log('error',e))

 app.service('todos').create({
   title: 'A message from a REST client'
 });

这个客户端代码让我得到find()和create()方法的超时错误

但如果我通过CURL发出POST请求,我在控制台中有 onCreated 消息

为什么我在create()和find()调用时遇到错误?

更新:

我使用git repo轻松重现此问题 https://github.com/tolyanor/feathersjs-error

UPDATE2:

我更改自动生成的文件src / app.js,如羽毛示例聊天应用程序https://github.com/feathersjs/feathers-chat/blob/master/src/app.js

现在我可以在客户端上调用service method create,但是不能接收 onCreated 消息。所以,这段代码

 app.service('/todos')
     .on('created', message => console.log('New todos created', message));

从不打电话

1 个答案:

答案 0 :(得分:2)

您正在使用Feathers v3客户端和Feathers v2服务器。旧客户端将向后兼容新服务器,但不是相反。按照migration guide升级服务器或使用@feathersjs/cli生成新应用程序(命令行上的feathers --version应显示v3.5.0或更高版本。