Connecting to compose.io rethinkDB server with thinky.io

244 views Asked by At

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

1

There are 1 answers

0
alex On

Using synchronous readFile

Solution using synchronous readFile:

One way of using thinky.io with compose.io when setting up a rethinkdb database is to use the synchronous readFile method when reading the ca Certificate before setting the thinky.io connection.

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;