egg中如何使用koa-socket?我知道有egg-socket,我想知道为什么有问题

Created on 9 May 2017  ·  8Comments  ·  Source: eggjs/egg

//我在app.js里面初始化koa-socket,代码如下
module.exports = app => {
var IO = require('koa-socket');
var io = new IO();
io.attach(app);
io.on( 'join', ( ctx, data ) => {
app.logger.info( 'join event fired', data )
})
}
然后客户端一直报 GET http://127.0.0.1:7001/socket.io/?EIO=3&transport=polling&t=Llh2ve7 跨域错误,我已经用koa-cors设置跨域了。客户端是没问题的,用koa+koa-socket试过了是可以的

egg-socket.io document

Most helpful comment

这个周末我补好吧

All 8 comments

使用 egg-socket.io 吧. egg是多进程的,必须要处理请求转发问题。

app 不是 server对象,这里没法attach吧

attach( app ) {

    if ( app.server && app.server.constructor.name != 'Server' ) {
      throw new Error( 'app.server already exists but it\'s not an http server' );
    }

attach 方法不对。egg的app没有server对象的。

@ngot 有空补一篇 socket.io 的 guide docs ?

这个周末我补好吧

@ngot 但是我启动并没有任何报错信息诶。 等你的guide docs 哦,我想知道怎么实现的。^_^

@ngot 这个文档有了么

@ngot egg-socket.io 的中间件支持下 async/await 吧

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wujianling picture wujianling  ·  3Comments

bupafengyu picture bupafengyu  ·  3Comments

popomore picture popomore  ·  3Comments

Leungkingman picture Leungkingman  ·  3Comments

kylezhang picture kylezhang  ·  3Comments