开发者

node.js making localhost client requests when system proxy is set

开发者 https://www.devze.com 2023-02-03 09:49 出处:网络
Here\'s the deal: I\'m using node.js to connect to a local CouchDB instance. The problem: the \"response\" event isn\'t firing. So I\'m assuming it\'s not getting a connection.

Here's the deal: I'm using node.js to connect to a local CouchDB instance.

The problem: the "response" event isn't firing. So I'm assuming it's not getting a connection.

var http = require('http'),
 sys = require('sys'),
 url = require('url');

var server = http.createServer(function (request, response) {
 var client = http.createClient(5984, '127.0.0.1'); // couchdb
 var request_db = client.request('GET', '/_all_dbs');
 console.log('Created a request for _all_dbs');
 request_db.addListener('response', function(response_db) {
  console.log('Some response from CouchDB');
 });
}).listen(8124);
console.log('Server running at http://127.0.0.1:8124/');

The only only output is:

Server running at http://127.0.0.1:8124/
C开发者_如何学Goreated a request for _all_dbs

I'm also guessing this might be a proxy problem. In Ubuntu 10.10, I have a system-wide proxy setting, but I tell it to ignore 127.0.0.1. Doing a curl on 127.0.0.1:5984/_all_dbs gives an error on "Error Code: 502 Proxy Error.".


First, try accessing 127.0.0.1:8124/_utils as @PartlyCloudy suggests.

Second, try using a couchdb lib such as cradle to make your life easier (and minimize mistakes)

npm install cradle

Remember to stop into #node.js and ask questions! Make sure to report back with your findings.


If you are using request to make the http request set proxy as empty string.. It will take preference over the system settings (you can do it only when the target ip is current machine ip)

var options = {
        agent: ...,
        url: ...,
        method: ...,
        proxy: ''
    };
var req= request(options);
.
.
.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号