【问题标题】:@feathersjs/socketio-client connection timeout. Why?@feathersjs/socketio-client 连接超时。为什么?
【发布时间】:2018-06-14 02:33:49
【问题描述】:

我做了跟随:

 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

更新2:

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

现在我可以在客户端调用服务方法创建,但不能接收 onCreated 消息。所以,这段代码

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

从不打电话

【问题讨论】:

    标签: feathersjs


    【解决方案1】:

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

    【讨论】:

    • 谢谢。我稍后再试
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-30
    • 1970-01-01
    • 2017-10-30
    • 1970-01-01
    • 1970-01-01
    • 2020-07-02
    相关资源
    最近更新 更多