Sunday, November 15, 2020

Loopback LB4, mysql SSL configuration

 I had a tough time trying to find documentation on how to configure loopback 4 to use SSL certs for communicating with a mySQL backend. So here's how I did it:



    dataSource: {  
     name: "mysql",  
     connector: "mysql",  
     // url: process.env.DS_URL, // don't use URL because SSL doesn't work with it  
     host: process.env.DB_HOST,  
     port: 3306,  
     ssl: {  
      rejectUnauthorized: false,  
      ca: fs.readFileSync(process.env.mysqlSSLCAcert, { encoding: 'utf8', flag: 'r' }),  
      key: fs.readFileSync(process.env.mysqlSSLClientKey, { encoding: 'utf8', flag: 'r' }), //client  
      cert: fs.readFileSync(process.env.mysqlSSLClientCert, { encoding: 'utf8', flag: 'r' }), // client  
     },  
     user: process.env.DB_USERNAME,  
     password: process.env.DB_PASSWORD,  
     database: "facility"  
    },