I'm running a Postgres DB and a node app on Heroku. When I try to do
app.use(session({
  store: new pgSession({
    conString: process.env.DATABASE_URL
  }),
  secret: 'my-super-secret-session',
  resave: false,
  cookie: {
    maxAge: 7 * 24 * 60 * 60 * 1000
  }
}));
I get a complaint: error: no pg_hba.conf entry for host "1.2.3.4", user ,myuser", database "mydb", SSL off
I assume I need to tell connect-pg-simple to use SSL somehow?
If you're not able to edit pg_hba.conf, because you're using a service like heroku, try this.
All you have to do is replace conString with conObject and specify a connectionString and ssl options.
app.use(session({
  store: new pgSession({
    conObject: {
      connectionString: process.env.DATABASE_URL,
      ssl: true,
    },
  }),
  secret: 'my-super-secret-session',
  resave: false,
  cookie: {
    maxAge: 7 * 24 * 60 * 60 * 1000
  }
}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With