2013-11-28 44 views
2

我刚刚在运行Win7(64位)的计算机上安装了node.js。node.js服务器正在运行但未加载

的问题是,当我运行它运行(由console.log()证实和我推代码OpenShift它工作得很好),但是当我尝试在localhost:1337只是加载网页它简单的hello世界中的应用继续加载(最终超时)。

我不知道该检查什么,因为防火墙是而不是阻塞节点,我没有运行阻塞端口的任何东西。

这是服务器代码。

#!/bin/env node 
// Include http module. 
var http = require("http"); 
//Get the environment variables we need if on OpenShift 
var ipaddr = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1"; 
var port = process.env.OPENSHIFT_NODEJS_PORT || 1337; 

http.createServer(function (request, response) { 
    request.on("end", function() { 
     response.writeHead(200, { 
     'Content-Type': 'text/plain' 
     }); 
     response.end('Hello HTTP!'); 
    }); 
}).listen(port, ipaddr); 

console.log('It works'); 
console.log('IP : ' + ipaddr + '\nPort : ' + port); 

任何帮助表示赞赏,谢谢。

编辑

这里的命令行输出的屏幕截图。 http://i.stack.imgur.com/GGaLD.png

回答

2

节点服务器挂起,因为您需要始终呼叫response.end

我认为收听request上的end事件会导致超时。如果你删除它会起作用。

+0

真的!这解决了这个问题,谢谢。不过,我感到困惑,为什么它在OpenShift上测试时工作? –

+0

@ user2978301我对OpenShift并不熟悉,但是这是有效的,因为浏览器没有关闭连接,因此'end'事件从不会触发 – Bulkan

相关问题