Connect my database with an certificate

Hi,
I have a database on which the connection must be made with a certificate.
In my .env I put this:

DATABASE_URL=mysql://user:mdp@host:port/db
DATABASE_SSL=true

But where do I specify the path to my certificate ?

Thank’s

Hi @Benjamin ! :wave:
You can edit the sequelize parameters in models/index.js, look for databaseOptions and try to add something like that :slight_smile:.

Ok good !
I did:

.env

DATABASE_URL=mysql://user:mdp@host:port/db
DATABASE_SSL=true
DATABASE_PATH_CA="../my/path/ca.crt"

models/index.js

if (process.env.DATABASE_SSL && JSON.parse(process.env.DATABASE_SSL.toLowerCase())) {
  databaseOptions.dialectOptions.ssl = {
    rejectUnauthorized: true,
    ca: fs.readFileSync(process.env.DATABASE_PATH_CA)
  };
}

It works nickel !

Thank’s

1 Like

Great ! Thanks for sharing an example :slight_smile: