brycelikesdogs
brycelikesdogs

Reputation: 151

Connecting to heroku psql database from local server - getting ssl error

I'm trying to connect to my postgreSQL database on heroku from my express app. This works fine when the express app is also deployed to heroku, but I can't connect to the database when running the express app locally.

const db = require('knex')({
  client: 'pg',
  connection: ${process.env.DATABASE_URL}?ssl=true,
});

I receive this error: err: Error: self signed certificate.

How can I solve this?

Upvotes: 1

Views: 540

Answers (2)

skoll
skoll

Reputation: 2452

Another option is to use

connection: {
  connectionString: process.env.DATABASE_URL,
  ssl: { rejectUnauthorized: false },
},

Upvotes: 0

brycelikesdogs
brycelikesdogs

Reputation: 151

So originally I was using a connection string, I changed to using this instead:

connection: {
    host: process.env.PRODUCTION_HOST,
    user: process.env.PRODUCTION_USER,
    password: process.env.PRODUCTION_PASSWORD,
    database: process.env.PRODUCTION_DATABASE,
    ssl: { rejectUnauthorized: false }
  },

when I had ssl: true it would not work. But then I changed it to the above where ssl: { rejectUnauthorized: false } and it seems to work fine for now.

Upvotes: 3

Related Questions