1

index.js:

var koa = require('koa')
  , Primus = require('primus.io')
  , http = require('http')
  , app = koa()
  , server = http.createServer(app);

var primus = new Primus(server, { transformer: 'websockets', parser: 'JSON' });

primus.on('connection', function (spark) {
  spark.send('news', { hello: 'world' });
  spark.on('my other event', function (data) {
    console.log(data);
  });
});

app.get('/', function (req, res) {
  res.sendfile(__dirname + '/index.html');
});

server.listen(8080);
console.log('8080');

跑:node --harmony index

和错误:throw TypeError('listener must be a function');

4

2 回答 2

3

您需要更改代码来执行此操作:

server = http.createServer(app.callback())

于 2015-08-13T14:51:40.847 回答
1

尝试:添加星号'*'

app.get('/',function*(next){})
于 2014-10-03T10:58:18.293 回答