使用SecureGateway将NodeJS应用程序与OracleDB连接 [英] Connecting NodeJS app with OracleDB using SecureGateway

查看:221
本文介绍了使用SecureGateway将NodeJS应用程序与OracleDB连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SecureGateway将NodeJS应用程序连接到Oracle DB,但无法正常工作.

I'm trying to connect my NodeJS app to a Oracle DB using SecureGateway but doesn't work.

我执行了测试,并在运行时

I executed tests, and when I run

var exec = require('child_process').exec;
var sys = require('sys');
function puts(error, stdout, stderr) { sys.puts(stdout) }
exec("ping 192.168.10.8", puts);

为了测试我的连接,我没有结果.因此,我认为不要在我的应用程序和网关之间建立连接.

for test my connection, I don't have results. So I think a don't created the connection between my app and my gateway.

当我在DataConnect中运行时,工作正常.

When I was running in DataConnect, works normally.

我使用require('bluemix-secure-gateway')从服务器获取信息.

I use require('bluemix-secure-gateway') for take the informations from my server.

用于创建隧道的功能是

const tls = require('tls');
const net = require('net');

var creations = 0;  // a running count of the number of open connections, when it becomes 0, the tunnel is closed.
var server;  // a server listening for certificate requests from the gateway server 

exports.create = function(port, options, callback) {
    if(creations == 0) {

        creations++;

        //server not currently running, create one
        server = net.createServer(function (conn) {
            connectFarside(conn, options, function(err, socket) {
                socket.pipe(conn);
                conn.pipe(socket);
            });
        });

        server.listen(port, function(){
            callback();
        });

    } else{
        //server already running
        creations++;
        callback()
    }
};

function connectFarside(conn, options, callback) {
    try {
        var socket = tls.connect(options, function() {
            callback(null, socket);
        });

        socket.on('error', function(err){
            console.log('Socket error: ' + JSON.stringify(err));
        });

    } catch(err) {
        callback(err);
    }
};

exports.close = function(){

    creations--;
    if(creations == 0){
        // close the server if this was 
        // the only connections running on it
        server.close();
    }
}

我得到的结果是我的本地网.

The result that I have is my local net.

推荐答案

要将应用程序扩展到Secure Gateway,只需使用目标提供的cloud host:port.为了接受连接,您需要在可以访问数据库的位置上运行安全网关客户端.

To have your application reach out to Secure Gateway, it just needs to use the cloud host:port provided by your destination. For the connection to be accepted, you need to have the Secure Gateway Client running in a location that can access your database.

例如,如果要连接到在本地计算机上运行的Mongo数据库,则可以创建一个目标,其中资源主机名设置为localhost,资源端口设置为27017.创建此目的地后,将为其分配一个云主机:端口(例如cap-sg-prd-3.integration.ibmcloud.com:23432).

For example, if I wanted to connect to a Mongo database running on my local machine, I could create a destination with the Resource Hostname set to localhost and the Resource Port set to 27017. Once this destination is created, it will be assigned a cloud host:port (e.g., cap-sg-prd-3.integration.ibmcloud.com:23432).

如果我的应用程序通常使用mongodb://localhost:27017/myproject之类的连接字符串连接到Mongo,我会将其更改为mongodb://cap-sg-prd-3.integration.ibmcloud.com:23432/myproject,以便通过安全网关路由该连接.

If my application usually connects to Mongo with a connection string like mongodb://localhost:27017/myproject, I would change that to mongodb://cap-sg-prd-3.integration.ibmcloud.com:23432/myproject so the connection will be routed via Secure Gateway.

这篇关于使用SecureGateway将NodeJS应用程序与OracleDB连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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