3

I have a Node / Express app with a Postgres database that functions perfectly on my local machine, but I'm struggling to get it up and running on Heroku. The problem occurs after I push to Heroku -- which builds successfully -- when I then try to run heroku run sequelize db:migrate. The error is:

ERROR: self signed certificate

My setup:

  • Node v15.12.0
  • Postgres database ("Heroku Postgres" add-on)
  • pg v8.5.1
  • sequelize v6.6.2
  • sequelize-cli v6.2.0

My Sequelize connection parameters:

{
  "development": {
    "username": "XXXXXX",
    "password": "XXXXXX",
    "database": "party_playlist",
    "host": "127.0.0.1",
    "dialect": "postgres"
  },
  "production": {
    "use_env_variable": "DATABASE_URL",
    "dialect": "postgres",
    "dialectOptions": {
      "ssl": {
         "require": "true",
         "rejectUnauthorized": "false"
      }
    }
  }
}

Many posts speak to this issue (GitHub: 1 | 2 | 3, StackOverflow: 1 | 2 | 3), and most point to pg v8 as being the root of the problem; however, none of the recommended solutions have worked for me.

What I've tried so far:

  1. Adding rejectUnauthorized: false to my Sequelize connection params
  2. Adding ssl:true to the config outside of dialectOptions
  3. Adding NODE_TLS_REJECT_UNAUTHORIZED=0 to my Heroku environment variables
  4. Adding PGSSLMODE=no-verify to my Heroku environment variables
  5. Toggling Heroku's Automatic Certificate Management feature on/off
  6. Rolling back to pg v7 (various subversions)

1-5 have no effect, and rolling back to pg v7 breaks the app (locally, any attempted reads/writes to the database hang with no error message; on heroku, the db:migrate command runs without an error message, but the db isn't updated). I assume that pg v7 is incompatible with my Node version or some other package version in my project, but I have no idea how to figure out what a compatible version set would be other than by trial and error, which isn't feasible. Also, as a side note, this is a hobby project so I'm not worried about MITM attacks.

Interestingly, I'm able to connect to my Heroku database just fine when I run heroku pg:psql!

Any ideas how I can fix this one? Any and all help would be much appreciated!

WithoutATowel
  • 157
  • 1
  • 8

2 Answers2

1

I saw your question from here and the accepted answer there worked for me. I observed that we have the same versions of pg and sequelize but not same version of node. I am on v14.8.0. I suggest you use nvm to switch to that version and try again as I have observed that node versions with odd numbers(like 13,15) often give issues(my observation might be wrong though).

camelCase
  • 475
  • 5
  • 14
1

This:

"ssl": {
    "require": "true",
    "rejectUnauthorized": "false"
 }

Should have been this:

"ssl": {
    "rejectUnauthorized": false
 }

Noting the quotes around the boolean.

Dumb mistake but I'll leave this up in case anyone else makes the same error someday.

WithoutATowel
  • 157
  • 1
  • 8