Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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)
share|improve this question

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.

share|improve this answer
    
I tried that with no luck: {"db":{"name":"db","connector":"memory"},"mydb":{"host":"myh‌​ost","port":####,"ur‌​l":"myamazonawsurl:#‌​###/mydbname","datab‌​ase":"mydbname","pas‌​sword":"mypw","name"‌​:"mydatasourcename",‌​"ssl":true,"user":"m‌​yuser","connector":"‌​postgresql"}} – woodlumhoodlum Jul 15 '15 at 6:58
    
Can you update your question with what you put in datasources.json? Comments don't format JSON well. If you can also post the error you get it'll help. Based on what you pasted I don't think you've entered it correctly. – elithrar Jul 15 '15 at 6:59
    
yeah, sorry about that. Added them. StrongLoop's UI automatically places the connection strings in their fields in the datasources.json. I manually added the "ssl": true to the file. – woodlumhoodlum Jul 15 '15 at 7:10
    
Please note that url property shadows other configuration attributes. You should make them part of the url as query params, for example: "url": "postgres://user:[email protected]:5‌​432/your-db-name?ssl‌​=true", – Raymond Feng Jul 15 '15 at 7:10
    
right @RaymondFeng I agree it's much cleaner, but beyond adding the ssl key there is still something on heroku side that must need configuring. – woodlumhoodlum Jul 15 '15 at 7:17

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

$ export PGSSLMODE=require
share|improve this answer

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

"devpostgresql": {
    "url": "postgres://user:[email protected]:5432/dbname?ssl=true",
    "name": "devpostgresql",
    "connector": "postgresql"
  }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.