Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SequelizeConnectionError: The server does not support SSL connections

I am trying to connect my project with PostgreSQL but show this error. Please help me I have installed Postgres.app and for GUI PgAdmin.

Unhandled rejection SequelizeConnectionError: The server does not support SSL connections
        at /Users/inamur/Documents/Project/project-api/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:186:20
        at Connection.connectingErrorHandler (/Users/inamur/Documents/Project/project-api/node_modules/pg/lib/client.js:203:14)
        at Connection.emit (events.js:223:5)
        at Connection.EventEmitter.emit (domain.js:475:20)
        at Socket.<anonymous> (/Users/inamur/Documents/Project/project-api/node_modules/pg/lib/connection.js:90:21)
        at Object.onceWrapper (events.js:313:26)
        at Socket.emit (events.js:223:5)
        at Socket.EventEmitter.emit (domain.js:475:20)
        at addChunk (_stream_readable.js:309:12)
        at readableAddChunk (_stream_readable.js:290:11)
        at Socket.Readable.push (_stream_readable.js:224:10)
        at TCP.onStreamRead (internal/stream_base_commons.js:181:23)

This is my .env file

JWT_SECRET='UserNews'
DB_LINK='postgres://root:root@localhost:5432/SCROLL001?ssl=true'

This is connection file.

const sequelize = new Sequelize(process.env.DB_LINK, {
  dialect: 'postgres',
  protocol: 'postgres',
  dialectOptions: {
    ssl: {
      require: 'true'
    }
  }
});
like image 955
Inamur Rahman Avatar asked Apr 11 '20 07:04

Inamur Rahman


3 Answers

I have solved the issue.

const sequelize = new Sequelize(process.env.DB_LINK, {
  dialect: 'postgres',
  protocol: 'postgres',
  dialectOptions: {}, //removed ssl
});

Change the DB Link

DB_LINK='postgres://root:root@localhost:5432/SCROLL001'
like image 163
Inamur Rahman Avatar answered Nov 08 '22 02:11

Inamur Rahman


You haven`t used dialectOptions correctly.

Just make the following changes:

const sequelize = new Sequelize(process.env.DB_LINK, {
  dialect: 'postgres',
  protocol: 'postgres',
  dialectOptions: {
    ssl: true,
    native:true
  }
});

native flag for using a native library or not.In the case of 'pg' -- set this to true will allow SSL support, default value is false. reference link

like image 2
Prabhjot Singh Kainth Avatar answered Nov 08 '22 04:11

Prabhjot Singh Kainth


It is recommended to use SSL for connections in production applications. You can continue to use an SSL connection using while circumventing it locally using:

const sequelize = new Sequelize(process.env.DB_LINK, {
  dialect: 'postgres',
  protocol: 'postgres',
  ssl: process.env.DB_ENABLE_SSL,
  dialectOptions: {
    ssl: process.env.DB_ENABLE_SSL && {
      require: true
    }
  }
});
like image 2
Danny Sullivan Avatar answered Nov 08 '22 03:11

Danny Sullivan