我在Heroku上运行Postgres数据库和节点应用程序。当我尝试做的时候
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
}
}));
我得到了一个投诉:error: no pg_hba.conf entry for host "1.2.3.4", user ,myuser", database "mydb", SSL off
我想我需要告诉connect-pg-simple
以某种方式使用SSL?
如果你无法编辑pg_hba.conf
,因为你正在使用像heroku这样的服务,试试这个。
你所要做的就是用conString
替换conObject
并指定connectionString
和ssl
选项。
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
}
}));
您需要在pg_hba.conf中添加一个条目以允许您的连接。
例:
vi $PGDATA/pg_hba.conf
host all all 1.2.3.4/32 md5
保存此配置文件后,您需要通过发出config reload命令重新加载它:
pg_ctl reload
然后重试连接。