简体   繁体   中英

SSL connection is required. Please specify SSL options and retry

I use azure postgres, so when I disable SSL it works fine but I want SSL connection enabled and when I enable from azure and then when I start my application ERROR: SSL connection is required. Please specify SSL options and retry SSL connection is required. Please specify SSL options and retry This error occurs multiple time

where in docs of azure Azure Docs for SSL . here is my connection string

connection: {
        database: process.env.POSTGRES_DATABASE || 'postgres',
        port: process.env.POSTGRES_PORT || 5432,
        user: process.env.POSTGRES_USER || 'my@-username',
        host: process.env.POSTGRES_HOST || 'postgres.db.postgres.database.azure.com',
        password: process.env.POSTGRES_PASSWORD || 'postpass',
        sslmode: 'require',
        }

as per azure docs i specify that sslmode:require but its not working is anyone face the same error and got the solution then let me know, I stuck into this error from last 5 days.

Regarding the issue, please refer to the following steps

  1. Download the SSL certificate . For more details, please refer to here

  2. Code

const pg = require("pg");
const fs = require("fs");
const config = {
  host: "<>.postgres.database.azure.com",
  user: "<>",
  password: "<>",
  database: "postgres",
  port: 5432,
  ssl: {
    cert: fs.readFileSync("<the cert path>"),
    rejectUnauthorized: true,
  },
};

const client = new pg.Client(config);

client.connect((err) => {
  if (err) throw err;
  else {
    console.log("success");
  }
});
const query = "SELECT * FROM inventory;";

client
  .query(query)
  .then((res) => {
    const rows = res.rows;
    console.log(`Read: ${JSON.stringify(rows)}`);
    process.exit();
  })
  .catch((err) => {
    console.log(err);
  });

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM