How to use DocumentDB behind a Proxy in NodeJS

大憨熊 提交于 2019-12-11 06:00:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!