postgresql - 我可以配置 connect-pg-simple 以启用 SSL 吗?

标签 postgresql session heroku connect

我在 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
  }
}));

我收到投诉:错误:主机“1.2.3.4”、用户、myuser、数据库“mydb”、SSL 关闭没有 pg_hba.conf 条目

我假设我需要告诉 connect-pg-simple 以某种方式使用 SSL?

最佳答案

如果您无法编辑 pg_hba.conf,因为您使用的是像 heroku 这样的服务,请试试这个。

您所要做的就是将 conString 替换为 conObject 并指定 connectionStringssl 选项。

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
  }
}));

关于postgresql - 我可以配置 connect-pg-simple 以启用 SSL 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39124709/

相关文章:

java - 使用 PostgreSQL COPY JDBC 防止 SQL 注入(inject)

java - 管理多个选项卡的 webapp session 数据/ Controller 流

django - Heroku Django 应用程序返回错误 heroku/router : at=error code=H10 desc ="App crashed"

Postgresql 并与空字段进行比较

sql - 更新 postgreSQL 首字母大写的列

php - 在 session 中存储 CSRF key ?

python - SQLAlchemy:直接从一对多关系中删除对象,而不使用 session.delete()

mysql - 为了 Heroku,从 MySQL 切换到 PostgreSQL for Ruby on Rails

docker - Heroku 上的 "No command specified for process type web"

sql - 仅返回列中的数值 - Postgresql