在 NodeJS 中,我尝试使用 Documentdb 库连接到 Cosmos DB,正如 Azure 文档的入门指南在 TODO 列表示例中所述。 Tutorial Here
如果我使用的互联网不在代理后面,它就可以工作。
这是连接代码:
var DocumentDBClient = require('documentdb').DocumentClient;
var docDbClient = new DocumentDBClient(config.host, {
masterKey: config.authKey
});
但是当我位于代理后面时,连接永远不会发生。我收到“错误:连接 ETIMEDOUT”
在其他 Node JS 应用程序中,如果我想发出 Web 服务请求,我只需为请求配置代理即可。例如请求:
request = require('request').defaults({
proxy:'http://USERNAME:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4414051717130b16000434362b3c3d6a3136286a272b29" rel="noreferrer noopener nofollow">[email protected]</a>:8080',
});
有没有办法在 DocumentDB 中配置代理以连接到 Azure (NodeJS) 中的数据库?
最佳答案
我没有亲自尝试过,但我在查看 SDK 的源代码时发现 ConnectionPolicy
有一个名为 ProxyUrl
的参数。您可以尝试以下操作吗:
var connectionPolicy = new DocumentBase.ConnectionPolicy();
connectionPolicy.ProxyUrl = 'http://USERNAME:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="81d1c0d2d2d6ced3c5c1f1f3eef9f8aff4f3edafe2eeec" rel="noreferrer noopener nofollow">[email protected]</a>:8080';
var docDbClient = new DocumentDBClient(config.host, {
masterKey: config.authKey
}, connectionPolicy);
关于node.js - 如何在 NodeJS 中的代理后面使用 DocumentDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51425340/