Feathers: Postgres SSL

Created on 26 Feb 2016  路  14Comments  路  Source: feathersjs/feathers

I'd like to use an Heroku remote db, so regarding https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-node-js I have to add an ?ssl=true at the end of the DB URL.

Unfortunately, I still have an ssl is off error at npm start

Bug

Most helpful comment

Just posting here what @amingilani posted in the thread @daffl shared:

const sequelize = new Sequelize(connectionString, {
  dialect: 'postgres',
  dialectOptions: {
    ssl: true
  }
});

All 14 comments

How does your setup look like? Are you using feathers-sequelize or feathers-knex?

Hi @daffl I'm using feathers-sequelize

{
  "host": "localhost",
  "port": 3030,
  "postgres": "postgres://user:[email protected]:5432/de5mmehm3q7rtc?ssl=true",
  "public": "../public/",
  "auth": {
    "token": {
      "secret": "......"
    },
    "local": {}

  }
}

I first tried business-stack where the config file is https://github.com/enspiral-craftworks/business-stack/blob/master/config/development.js

With this boilerplate I just had to add a ssl:true inside db:connection

Maybe is there a way to define the connection this way with feather ?

@naptiv can you post the error please? I haven't had a chance to test this with Heroku Postgres yet but might later today or this weekend.

Sure,

Feathers application started on localhost:3030
Unhandled rejection SequelizeConnectionError: no pg_hba.conf entry for host "ip", user "username", database "dbname", SSL off
    at /Users/naptiv/unlock/api/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:101:20
    at null.<anonymous> (/Users/naptiv/unlock/api/node_modules/pg/lib/client.js:176:5)
    at emitOne (events.js:77:13)
    at emit (events.js:169:7)
    at Socket.<anonymous> (/Users/naptiv/unlock/api/node_modules/pg/lib/connection.js:109:12)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:146:16)
    at Socket.Readable.push (_stream_readable.js:110:10)
    at TCP.onread (net.js:523:20)

@naptiv thanks. That does help a bit. I'll see if I can reproduce.

I tried to deploy Feathers to Heroku in order to avoid the SSL parameter but I ran into an other issue.

When running on heroku I have to use the port specified in the PORT environment variable : process.env.PORT which can't be set in the json file.

You should be able to. On Heroku you set NODE_ENV to production and then in config/production.json you can set "port": "PORT" which will try to read that environment variable. This is documented in https://github.com/feathersjs/feathers-configuration but I still have to add it to the main documentation.

Hopefully this works. I'm going to close this one. Feel free to reopen or add another issue if you have any other questions.

So, no SSL?

Of course. It looks like you need to use the pg-native driver for Sequelize (here is another issue).

The option to set once changed to the pg-native driver is

dialectOptions: { ssl: true }

Just posting here what @amingilani posted in the thread @daffl shared:

const sequelize = new Sequelize(connectionString, {
  dialect: 'postgres',
  dialectOptions: {
    ssl: true
  }
});

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings