【问题标题】:Connecting to compose.io rethinkDB server with thinky.io使用 thinky.io 连接到 compose.io rethinkDB 服务器
【发布时间】:2016-09-05 04:01:56
【问题描述】:

我正在尝试使用 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连接到 r.connect(),然后将现有连接与 thinky.io 一起使用?

我的 node.js 服务器托管在 heroku 上。

谢谢

【问题讨论】:

    标签: javascript node.js rethinkdb compose-db thinky


    【解决方案1】:

    使用同步读取文件

    使用同步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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多