Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I configure connect-pg-simple to have SSL on?

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?

like image 854
Shamoon Avatar asked Oct 27 '25 13:10

Shamoon


1 Answers

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
  }
}));
like image 132
obedm503 Avatar answered Oct 30 '25 12:10

obedm503