Connecting NodeJS app with OracleDB using SecureGateway

北城余情 提交于 2019-12-11 14:30:58

问题


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.

When I was running in DataConnect, works normally.

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

The function that is used for create the tunnel are

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.


回答1:


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.

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).

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.



来源:https://stackoverflow.com/questions/45040106/connecting-nodejs-app-with-oracledb-using-securegateway

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