MYSQL Database SSL

Hi!

im trying to use a ssl connection with my databas eon heroku and with the config like:

  mysql: {
    client: 'mysql',
    connection: {
      host: Env.get('DB_HOST', CLEARDB_DATABASE_URL.host),
      port: Env.get('DB_PORT', ''),
      user: Env.get('DB_USER', CLEARDB_DATABASE_URL.username),
      password: Env.get('DB_PASSWORD', CLEARDB_DATABASE_URL.password),
      database: Env.get('DB_DATABASE', CLEARDB_DATABASE_URL.pathname.substr(1)),
      ssl: {
        ca: fs.readFileSync(__dirname + '/certs/ca.pem'),
        key: fs.readFileSync(__dirname + '/certs/client-key.pem'),
        cert: fs.readFileSync(__dirname + '/certs/client-cert.pem')
      }
    },
  },

I have some errors on startup:

RuntimeException: E_MISSING_CONFIG: logger.transport is not defined inside config/app.js file
> More details: https://err.sh/adonisjs/errors/E_MISSING_CONFIG


1 Function.missingConfig
  C:\Users\vinicius\code\indicadores-producao\node_modules\@adonisjs\generic-exceptions\src\RuntimeException.js
:38

2 LoggerFacade.transport
  C:\Users\vinicius\code\indicadores-producao\node_modules\@adonisjs\framework\src\Logger\Facade.js:90

3 Object.get
  C:\Users\vinicius\code\indicadores-producao\node_modules\@adonisjs\framework\src\Logger\Facade.js:41

4 new Server
  C:\Users\vinicius\code\indicadores-producao\node_modules\@adonisjs\framework\src\Server\index.js:41

5 Object.app.singleton [as closure]
  C:\Users\vinicius\code\indicadores-producao\node_modules\@adonisjs\framework\providers\AppProvider.js:149

6 Ioc._resolveBinding
  C:\Users\vinicius\code\indicadores-producao\node_modules\@adonisjs\fold\src\Ioc\index.js:231

7 Ioc.use
  C:\Users\vinicius\code\indicadores-producao\node_modules\@adonisjs\fold\src\Ioc\index.js:731

8 ValidationProvider.boot
  C:\Users\vinicius\code\indicadores-producao\node_modules\@adonisjs\validator\providers\ValidatorProvider.js:8
7

9 _.filter.map
  C:\Users\vinicius\code\indicadores-producao\node_modules\@adonisjs\fold\src\Registrar\index.js:147

10 arrayMap
  C:\Users\vinicius\code\indicadores-producao\node_modules\lodash\lodash.js:639

11 Function.map
  C:\Users\vinicius\code\indicadores-producao\node_modules\lodash\lodash.js:9556

12 interceptor
  C:\Users\vinicius\code\indicadores-producao\node_modules\lodash\lodash.js:16993

13 thru
  C:\Users\vinicius\code\indicadores-producao\node_modules\lodash\lodash.js:8797

14 anonymous
  C:\Users\vinicius\code\indicadores-producao\node_modules\lodash\lodash.js:4374

15 arrayReduce
  C:\Users\vinicius\code\indicadores-producao\node_modules\lodash\lodash.js:683

16 baseWrapperValue
  C:\Users\vinicius\code\indicadores-producao\node_modules\lodash\lodash.js:4373

Application crashed, make sure to kill all related running process, fix the issue and re-run the app

Is there any way to do this?

1 Like

Two things I would check based on the error:

  1. Check to see if you accidentally removed/edited the logger config in config/app.js, the transport value needs to be either console or file.

  2. I would also check if you have .env file with a key generated.

2 Likes

Hi, i have not removed anything from config/app.js, i checked the log config there, its on defaults, i think its a bug.

I will reproduce this on a blank project and post the project on github later.

1 Like

I am using a managed database from Digital Ocean that requires a connection over SSL. Here is how I did it: https://stackoverflow.com/questions/61576522/adonis-how-to-connect-with-ssl-with-a-certificate-crt-file-to-mysql/61576531#61576531

/**************************************************************************
 * IMPORTS
 ***************************************************************************/

// NPM
const fs = require('fs')

// Providers
const Env = use('Env')

/**************************************************************************
 * CONFIG > DATABASE
 ***************************************************************************/

const config = {
  connection: Env.get('DB_CONNECTION', 'mysql'),

  mysql: {
    client: 'mysql',

    connection: {
      host: Env.get('DB_HOST', 'localhost'),
      port: Env.get('DB_PORT', ''),
      user: Env.get('DB_USER', 'root'),
      password: Env.get('DB_PASSWORD', ''),
      database: Env.get('DB_DATABASE', 'adonis'),
    },

    debug: Env.get('DB_DEBUG', false),
  },
}

// Add certificate for production environment
if (Env.get('NODE_ENV') === 'production') {
  config.mysql.connection.ssl = {
    ca: fs.readFileSync(__dirname + '/certs/ca-database.crt'),
  }
}

module.exports = config
1 Like