问题
In NodeJS I`m trying to connect to a Cosmos DB using the Documentdb library, as the getting starter of the azure documentation says in the TODO List Example. Tutorial Here
If I use an Internet that is not behind a proxy it works.
This is the connection code:
var DocumentDBClient = require('documentdb').DocumentClient;
var docDbClient = new DocumentDBClient(config.host, {
masterKey: config.authKey
});
But when I'm behind a proxy, the connection never occur's. I`m getting an "Error: connect ETIMEDOUT"
In other node JS apps, if I want to make a request of a webservice, I just configure the proxy for the request. For example with request:
request = require('request').defaults({
proxy:'http://USERNAME:PASSWORD@proxy.url.com:8080',
});
Is there a way to configure the proxy in DocumentDB to connect to the DB in Azure (NodeJS)?
回答1:
I've not personally tried it but I was going through the source code of the SDK and found out that ConnectionPolicy
has a parameter called ProxyUrl
. Can you try something like the following:
var connectionPolicy = new DocumentBase.ConnectionPolicy();
connectionPolicy.ProxyUrl = 'http://USERNAME:PASSWORD@proxy.url.com:8080';
var docDbClient = new DocumentDBClient(config.host, {
masterKey: config.authKey
}, connectionPolicy);
来源:https://stackoverflow.com/questions/51425340/how-to-use-documentdb-behind-a-proxy-in-nodejs