javascript - 使用 thinky.io 连接到 compose.io rethinkDB 服务器

标签 javascript node.js rethinkdb compose-db thinky

我正在尝试使用 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.iocompose.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/

相关文章:

html - 如何使用 Javascript 转换 html 中的重音字符?

javascript - MEANJS 获取 URL 参数

python - RethinkDB 中带有 lambda 的多个过滤器

go - 使用 gorethink 在查询之间创建

node.js - 有没有更好的方法使用 NodeJs 从 Telegram 机器人获取更新?

docker - Docker文件中的Tee命令

javascript - ngModelOptions 在指令中不起作用

javascript - 使用 Javascript/Jquery 进行捏合和缩放,无需插件

javascript - 加载后旋转谷歌广告

node.js - Angular-cli AOT 构建失败,出现 "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory"