2
votes

I am new to the world of Node.js, and have setup an app running on Heroku(free) using StrongLoop. I setup the heroku postgresql addon (free tier), and tried to add the datasource to StrongLoop's arc composer UI. This UI updates the server/datasources.json. When I try connecting to my datasource I get this error:

no pg_hba.conf entry for host "X.X.X.X", user "myUser", database "mydb", SSL off

I understand that the problem must be with setting up SSL on postgres. The closest StrongLoop documentation doesn't quite discuss this: https://strongloop.com/strongblog/postgresql-node-js-apis-loopback-connector/ ... Because I'm using StrongLoop rather than just straight Node.js, Heroku's documentation also left me lacking https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-node-js. I'm confused as to what I need to do exactly from here.

I have fairly simplistic newsfeed type JSON data that I manipulate with handlebars. So if it's an issue with being on the free tier, I'm open to other free suggestions with my setup. I appreciate your help.

Edit, datasources.json:

{"db":{"name":"db","connector":"memory"},
"mydb":{
"host":"myhost",
"port":####,
"url":"myamazonawsurl:####/mydbname",
"database":"mydbname",
"password":"mypw",
"name":"mydatasourcename",
"ssl":true,
"user":"myuser",
"connector":"postgresql"}}

More error details:

error: no pg_hba.conf entry for host "X.X.X.X", user "myuser", database "mydb", SSL off at 
Connection.parseE (c:\myroot\node_modules\loopback-connector-postgresql\node_modules\pg\lib\connection.js:539:11) at 
Connection.parseMessage (c:\myroot\node_modules\loopback-connector-postgresql\node_modules\pg\lib\connection.js:366:17) at 
Socket.<anonymous> (c:\myroot\node_modules\loopback-connector-postgresql\node_modules\pg\lib\connection.js:105:22) at 
Socket.emit (events.js:107:17) at readableAddChunk (_stream_readable.js:163:16) at 
Socket.Readable.push (_stream_readable.js:126:10)
5

5 Answers

5
votes

It should be "?ssl=true" not "?sslmode=require"

"devpostgresql": {
    "url": "postgres://user:[email protected]:5432/dbname?ssl=true",
    "name": "devpostgresql",
    "connector": "postgresql"
  }
3
votes

Based on the article you've linked, you'll need to modify your datasources.json configuration to suit your Heroku environment.

Get your details from heroku pg:credentials DATABASE_URL which will spit out the below (without the place-holders I've used, of course!):

postgres://user:[email protected]:5432/your-db-name

Paste that into datasources.json:

  "accountDB": {
     "connector": "postgresql",
     "url": "postgres://user:[email protected]:5432/your-db-name?sslmode=require"
  }

The PostgreSQL docs for Loopback provide some further details - http://docs.strongloop.com/display/public/LB/PostgreSQL+connector - but the above should get you started.

2
votes

Require SSL for Postgres connections by setting the following environment variable in command line:

$ export PGSSLMODE=require
1
votes

I ran into similar problem myself and I found this solution to fix it for me. Similar to @Lieblingsfarbe's answer, but this is in Heroku CLI.

Go into Heroku CLI -> your app directory -> issue this command:

heroku config:set PGSSLMODE=require

Reference: Found it here after a few hours of trying and researching (https://stackoverflow.com/a/27732431/7430591)

0
votes

I tried doing all above options, but in my case I was using wrong driver for postgresql.

After checking my postgresql version, which is 10.4, I had to use the gradle configuration below:

compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5'