Heroku Postgres: Unhandled rejection Error: self signed certificate

Viewed 250

I'm trying to configure the PostgreSQL database with postgrator in node, using the connectionString in production. I've added the code for initialization in node

const postgrator = new Postgrator(migrationConfig);
postgrator.migrate('002', (err, migrations) => {
  if (err) {
    console.error(err);
  } else {
    console.log(migrations);
  }
  postgrator.endConnection();
});
const isDevelopment = process.env.NODE_ENV === 'development';

let migrationConfig;
if (isDevelopment) {
  migrationConfig = {
    "migrationDirectory": "migrations",
    "driver": "pg",
    "host": process.env.DEV_DB_HOST,
    "port": process.env.DEV_DB_PORT,
    "database": process.env.DEV_DB_DATABASE,
    "username": process.env.DEV_DB_USER,
    "password": process.env.DEV_DB_PASS,
    "ssl": !isDevelopment,
  }
} else {
  migrationConfig = {
    "migrationDirectory": "migrations",
    "driver": "pg",
    "connectionString": process.env.DATABASE_URL,
    "ssl": true,
  }
}

I'm not sure why I'm getting the self signed certificate error on production.

2020-10-18T10:04:49.845485+00:00 app[web.1]: > export NODE_ENV=production && nodemon src/server.js
2020-10-18T10:04:49.845485+00:00 app[web.1]: 
2020-10-18T10:04:50.082326+00:00 app[web.1]: [nodemon] 2.0.4
2020-10-18T10:04:50.083611+00:00 app[web.1]: [nodemon] to restart at any time, enter `rs`
2020-10-18T10:04:50.084275+00:00 app[web.1]: [nodemon] watching path(s): *.*
2020-10-18T10:04:50.084383+00:00 app[web.1]: [nodemon] watching extensions: js,mjs,json
2020-10-18T10:04:50.085033+00:00 app[web.1]: [nodemon] starting `node src/server.js`
2020-10-18T10:04:50.489740+00:00 app[web.1]: Express is listening on port 48474
2020-10-18T10:04:50.535273+00:00 app[web.1]: Unhandled rejection Error: self signed certificate
2020-10-18T10:04:50.535275+00:00 app[web.1]: at TLSSocket.onConnectSecure (_tls_wrap.js:1502:34)
2020-10-18T10:04:50.535276+00:00 app[web.1]: at TLSSocket.emit (events.js:314:20)
2020-10-18T10:04:50.535276+00:00 app[web.1]: at TLSSocket._finishInit (_tls_wrap.js:937:8)
2020-10-18T10:04:50.535277+00:00 app[web.1]: at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:711:12)
2020-10-18T10:04:51.077573+00:00 heroku[web.1]: State changed from starting to up

I've upgraded the dyno to a paid service to activate the SSL, yet this error still continues to come up. I saw online suggestin to set rejectUnauthorized to false`, but postgrator does not provide that option. Even if I set it to the Postgres configuration the issue seems to still persist.

How do I fix this?

0 Answers
Related