我正在尝试使用 thinky.io 连接到 compose.io 上托管的 rethinkDB 服务器
根据文档,我可以使用 r.connect 连接以下内容:
const r = require('rethinkdb');
const fs = require('fs');
fs.readFile('../cacert', function(err, caCert) {
r.connect({
authKey: 'MY_KEY',
host: 'aws-us-east-1-portal.5.dblayer.com',
port: 11190,
ssl: {
ca: caCert
}
}, function(error, conn) {
r.dbList().run(conn, function(err, results) {
console.log(results);
})
})
});
但是,当使用 thinky.io 时,它不会使用 SSL 证书,我会使用以下不起作用的连接:
const thinky = require('thinky')({
authKey: 'MY_KEY',
host: 'aws-us-east-1-portal.5.dblayer.com',
port: 11190,
});
有什么方法可以使用 thinky.io 连接到 compose 或使用 r.connect()
连接,然后使用与 thinky.io 的现有连接?
我的node.js 服务器托管在heroku 上。
谢谢
最佳答案
使用同步readFile
使用同步readFile的解决方案:
在设置 rethinkdb 数据库时,将 thinky.io 与 compose.io 结合使用的一种方法是使用 同步 readFile 设置 thinky.io 连接之前读取 ca 证书时的方法。
const fs = require('fs');
const config = require('../config')
const caCert = fs.readFileSync('cacert')
const thinky = require('thinky')({
authKey: config.authKey,
host: 'aws-us-east-1-portal.5.dblayer.com',
port: 11190,
ssl: {
ca: caCert
}
});
module.exports = thinky;
关于javascript - 使用 thinky.io 连接到 compose.io rethinkDB 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38803264/