Reputation: 43491
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?
Upvotes: 4
Views: 1041
Reputation: 128
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
}
}));
Upvotes: 4
Reputation: 1701
You need to add an entry in the pg_hba.conf to allow your connection.
Example:
vi $PGDATA/pg_hba.conf
host all all 1.2.3.4/32 md5
After saving this config file you will need to reload it by issuing a config reload command:
pg_ctl reload
Then retry the connection.
Upvotes: 1