[英]Connecting to a remote Oracle DB with Nodejs through Oracledb Driver
[英]Connecting NodeJS app with OracleDB using SecureGateway
我正在嘗試使用SecureGateway將NodeJS應用程序連接到Oracle DB,但無法正常工作。
我執行了測試,並在運行時
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);
測試我的連接,我沒有結果。 因此,我認為不要在我的應用程序和網關之間建立連接。
當我在DataConnect中運行時,可以正常工作。
我使用require('bluemix-secure-gateway')
從服務器獲取信息。
用於創建隧道的功能是
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();
}
}
我得到的結果是我的本地網。
要使您的應用程序連接到Secure Gateway,只需使用目的地提供的cloud host:port。 為了接受連接,您需要在可以訪問數據庫的位置運行安全網關客戶端。
例如,如果我想連接到在本地計算機上運行的Mongo數據庫,則可以創建一個目標,其中資源主機名設置為localhost
,資源端口設置為27017
。 創建此目的地后,將為其分配一個雲主機:端口(例如, cap-sg-prd-3.integration.ibmcloud.com:23432
: cap-sg-prd-3.integration.ibmcloud.com:23432
)。
如果我的應用程序通常使用mongodb://localhost:27017/myproject
類的連接字符串連接到Mongo,我將其更改為mongodb://cap-sg-prd-3.integration.ibmcloud.com:23432/myproject
因此連接將通過安全網關進行路由。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.