1

I am trying to connect to a hosted rethinkDB server on compose.io using thinky.io

According to the docs I can connect with the following using 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);
    })
  })
});

However when using thinky.io it will not take an SSL certificate, and I would connect using the following which does not work:

const thinky = require('thinky')({
  authKey: 'MY_KEY',
  host: 'aws-us-east-1-portal.5.dblayer.com',
  port: 11190,
});

Is there any way I can connect to compose using thinky.io or connect using r.connect() and then use that existing connection with thinky.io?

My node.js server is hosted on heroku.

Thanks

4

1 回答 1

1

使用同步 readFile

使用同步readFile的解决方案:

在设置rethinkdb数据库时使用thinky.iocompose.io的一种方法是在设置 thinky.io 连接之前读取 ca 证书时使用同步 readFile方法。

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;
于 2016-08-06T13:21:08.650 回答