【问题标题】:node+now.js+connect gives me an errornode+now.js+connect 给我一个错误
【发布时间】:2012-06-05 08:12:38
【问题描述】:

我安装了 node_module connect 以使用静态方法。这是我的代码:

var http = require('http');
var connect = require('connect');
var nowjs = require("now");
var app = connect();

app.use(connect.static('/var/www/www.domain.com/htdocs'));

app.use(function(req, res){
    res.end();
});

http.createServer(app).listen(8001);


var everyone = nowjs.initialize(http);

但我得到一个错误:

[TypeError: Object #<Object> has no method 'listeners'] TypeError: Object #<Object> has no method 'listeners'
    at Object.wrapServer (/home/chris/nowjs/node_modules/now/lib/fileServer.js:23:29)
    at [object Object].initialize (/home/chris/nowjs/node_modules/now/lib/now.js:181:14)
    at Object.<anonymous> (/home/chris/nowjs/multiroomchat_server.js:15:22)
    at Module._compile (module.js:446:26)
    at Object..js (module.js:464:10)
    at Module.load (module.js:353:31)
    at Function._load (module.js:311:12)
    at Array.0 (module.js:484:10)
    at EventEmitter._tickCallback (node.js:190:38)

怎么了?

【问题讨论】:

  • 这有帮助吗? var server = http.createServer(app).listen(8001); var everyone = nowjs.initialize(server);
  • 是的!谢谢!请将其发布为答案,以便我批准:)
  • 以下一个问题:它与 .html 文件一起工作正常,但如果我打开 localhost:3000/test.php 它会给我 test.php 下载..
  • 打开 test.php 后会发生什么? connect.static 肯定不会运行 PHP 解释器。
  • 是的,显然......但它是否有可能也适用于 .php 文件?

标签: node.js connect nowjs-sockets


【解决方案1】:

http 变量是对 http 模块的引用,而不是创建的 http 服务。您需要获取从 createServer() 传回的变量并将其传递给 Now.js。谢天谢地,listen() 锁住了它,你不必拆线。

var server = http.createServer(app).listen(8001);
var everyone = nowjs.initialize(server);

【讨论】:

    猜你喜欢
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 2012-06-13
    • 1970-01-01
    • 2015-01-22
    相关资源
    最近更新 更多