Search code examples
mysqlexpresssslheroku

Planetscale post request error 'client must use SSL/TLS'


Using tools

  1. Planetscale MySQL cloud database
  2. Express
  3. Swagger
  4. Heroku

I tried to send a post request to server from postman and swagger api doc. But I got this error for both.

unknown error: Code: UNAVAILABLE
server does not allow insecure connections, client must use SSL/TLS

I could send post requests when using localhost. But after deploying app on heroku, I cannot do that anymore.


Solution

  • In the documentation explain how to load the certificates

    const sequelize = new Sequelize({
        dialect: 'mysql',
        username: MYSQL_USER,
        password: MYSQL_PASSWORD,
        host: MYSQL_HOST,
        dialectOptions: {
            bigNumberStrings: true,
            ssl: {
              ca: fs.readFileSync(__dirname + '/ca-certificates.crt')
            }
        }
    })