Mikro-orm: Support for SSL in Postgres connections

Created on 18 Jan 2020  路  6Comments  路  Source: mikro-orm/mikro-orm

Hello,

I'm having an issue connecting to a hosted DigitalOcean Postgres server, which requires SSL, but I can't seem to find a way to enable it currently in init() options. Is there a way to do this, or a workaround?

Thanks in advance!

question

Most helpful comment

In case someone comes with a problem on heroku, or getting UnhandledPromiseRejectionWarning: DriverException: self signed certificate for some other reason, here is the fix

driverOptions: {
  connection: { ssl: { rejectUnauthorized: false } },
},

All 6 comments

You could probably use driverOptions for that (if you can achieve that in knex, then this allows you to pass additional options to knex).

https://mikro-orm.io/docs/configuration/#driver

You could try something like:

MikroORM.init({
  // ...
  driverOptions: {
    connection: { ssl: true },
  },
});

There are some issues about this in knex's repository, you should take a look there. One suggests to use environment variable for this:

Workaround which worked for me: set environment variable PGSSLMODE=require. It forces postgres driver to use SSL and it resolved the issue at least in my case. Still waiting for the official patch though.

https://github.com/knex/knex/issues/852

@DmiPet did it work for you?

Hi @B4nan, thanks so much for the suggestions! Setting environment variable PGSSLMODE=require did the trick 馃憤

@DmiPet did it work for you?

In case anyone else prefers to have their database connection config in the Mikro config, adding these to driverOptions works for me:

{
  connection: {
    ssl: true
  }
}

In case someone comes with a problem on heroku, or getting UnhandledPromiseRejectionWarning: DriverException: self signed certificate for some other reason, here is the fix

driverOptions: {
  connection: { ssl: { rejectUnauthorized: false } },
},
Was this page helpful?
0 / 5 - 0 ratings

Related issues

gustavopch picture gustavopch  路  4Comments

jsprw picture jsprw  路  6Comments

sptGabriel picture sptGabriel  路  4Comments

Langstra picture Langstra  路  4Comments

rubiin picture rubiin  路  7Comments