使用节点代理时出错

error while using node proxy

我正在使用以下程序,当我 运行 它时出现以下错误我能够 运行 该应用程序但是当我放入浏览器时 localhost:3000 我收到此错误在控制台中...

**Error: connect ECONNREFUSED**
    at exports._errnoException (util.js:746:11)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1000:19)

这是程序 我有一个非常简单的节点应用程序,只有一个文件包含以下代码(这是我的 server/app/.js

var http = require('http'),
    httpProxy = require('http-proxy'),
    url = require('url');

proxy = httpProxy.createProxyServer({});

http.createServer(function (req, res) {



    switch (hostname) {
        case 'localhost':
            proxy.web(req, res, {target: 'http://localhost:9001'});
            break;

    }
}).listen(3005, function () {
    console.log('original proxy listening on port: ' + 3005);
});


http.createServer(function(req, res) {
    res.end("Request received on 9001");
}).listen(9056);

我想在用户点击某些 URL

时启动新的代理服务器

我用这个模块,我做错了什么?

https://github.com/nodejitsu/node-http-proxy

另一件事...当我使用此代码时出现错误...

process.on('uncaughtException', function (err) {
    console.log(err);
});

这是现在的错误,知道吗?

{ [Error: connect ECONNREFUSED]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect' }
{ [Error: socket hang up] code: 'ECONNRESET' }
http.createServer(function(req, res) {
    res.end("Request received on 9001");
}).listen(9056);

您的 HTTP 服务器正在侦听端口 9056。代理尝试连接到错误端口上的 HTTP 服务器,并在无法建立连接时抛出错误。为避免将来出现此类错误,请将端口放入变量中:

var PORT = 9001;
http.createServer(function(req, res) {
    res.end("Request received on " + PORT);
}).listen(PORT);