首页 文章

无法使用节点示例从heroku本地连接到heroku postgres

提问于
浏览
1

我按照以下步骤操作:https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction

当我运行heroku本地它无法连接 - 我看到它正在使用process.env.DATABASE_URL并使用以下内容将其输入到我的本地.env文件:https://devcenter.heroku.com/articles/heroku-local

但它仍然无法连接,我添加了一个console.log来查看错误:

“错误:主机”62.90.xxx.yyy“没有pg_hba.conf条目,用户”用户名“,数据库”密码“,SSL关闭”

现在怎么办?

1 回答

  • 0

    经过大量搜索后发现,添加'pg.defaults.ssl = true'可以解决我的问题,同时让我尽可能接近Heroku提供的样本 .

    这是我的代码

    const cool = require('cool-ascii-faces');
    const express = require('express')
    const path = require('path')
    const PORT = process.env.PORT || 5000
    
    const pg = require('pg');
    pg.defaults.ssl = true; //this is it!!!
    
    express()
      .use(express.static(path.join(__dirname, 'public')))
      .set('views', path.join(__dirname, 'views'))
    ....
    

相关问题