使用SSH隧道连接与节点连接到Azure [英] Connecting to Azure with SSH Tunnel Connection with Node

查看:207
本文介绍了使用SSH隧道连接与节点连接到Azure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太了解节点。 我有一个我继承的应用程序需要连接到宇宙。以前它指向Linux框。

I don't know node too well.  I have an application that I inherited that needs to connect to cosmos. Previously it was pointing to Linux box.

代码如下所示:

 app.post('/save', function (req, res) {
        var config = {
            username: 'root',
            host: 'xx.xx.xx.xx',
            port: 22,
            password: 'password',
            dstHost: '127.0.0.1',
            dstPort: 27017,
            localPort:2000,

 };
        var server = tunnel(config, function (error, server) {

            if (error) {
                console.log("SSH connection error: " + error);
            }

            mongoose.connect('mongodb://127.0.0.1:2000/Hate');


 

所以我现在的假设是,这将改为:

So my assumption right now is that this would change to:

  app.post('/save', function (req, res) {
        var config = {
            username: 'username',
            host: 'host.documents.azure.com',
            //port: 10255,
            password: 'password',
            dstHost: 'host.documents.azure.com',
          dstPort: 10255,
            localPort: 2000,
        };
        var server = tunnel(config, function (error, server) {

            if (error) {
                console.log("SSH connection error: " + error);
            }

            mongoose.connect('mongodb://127.0.0.1:2000/Hate');

由于我的本地服务器不必通过ssh监听转发连接,我该怎么办才能使这个连接没有做太多更改?

Since my local server does not have to listen for connections to forward via ssh, what do I have to do make this thing connect without making too many changes?




推荐答案

嗨YummyYumYums,

Hi YummyYumYums,

您需要编写客户端逻辑以直接连接到Azure Cosmos DB MongoDB API,而不是在Linux主机上运行的MongoDB实例,但最简单的方法是运行它以更新mongoose.connect连接包含Mongo DB的Cosmos数据库实例的相关
连接字符串的字符串。

You will need to write client logic to connect to the Azure Cosmos DB MongoDB API directly and not to the MongoDB instance is running on the Linux host but, easiest way to get running it to update the mongoose.connect connection string with the relevant connection string for your Cosmos DB instance for Mongo DB.

mongoose 连接 'mongodb://127.0.0.1:2000 / Hate' );

以下文档将帮助您检索格式正确的猫鼬连接字符串: 

The following documentation will help you retrieve the correctly formatted mongoose connection string: 

获取使用快速入门的MongoDB连接字符串

如果您有其他问题,请告诉我们。

Please let us know if you have additional questions.

此致,

Mike

Mike


这篇关于使用SSH隧道连接与节点连接到Azure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆