The trick to setting up a Sails.js app with a remote Postgres database hosted on Heroku is all about SSL. Here's how you do it:
Note: This is for Sails v0.9.x, the stable release at the time of this writing.
In Sails v0.10.x, the
config/adapters.js
file has been replaced withconfig/connections.js
You'll also want to replace themodule
key withadapter
.It should work anyways, since backwards compatibility for the old config is built-in, but that compatibility will be dropped prior to v1.0, so you might as well set it up to use the latest and greatest.
// ....
'db-core': {
module: 'sails-postgresql',
host: process.env.PG_HOSTNAME' || localhost',
user: process.env.PG_USER || 'root',
password: process.env.PG_PASSWORD || '',
database: process.env.PG_DATABASE || 'name_of_your_db',
port: process.env.PG_PORT || 5432,
ssl: {
rejectUnauthorized: false
}
}
// ....
Hi,
This post may need to be updated. The current
heroku config
gives a different URL.e.g.
DATABASE_URL: postgres://vhsmxoldrngunv:G5Dhk-OEXaiBy6NRucg0DbuEQW@ec2-54-83-198-111.compute-1.amazonaws.com:5432/d3qir1r07g6hi7
Could you please suggest how to connect to this database using
connections.js
file.Sample connections file.