node.js 上的 Heroku 应用程序无法连接到 Heroku Postgre

时间:2021-05-15 18:46:46

标签: javascript node.js postgresql heroku

我正在使用 Heroku 和 PostgreSQL 编写一个 node.js 应用程序。但是当我尝试通过 Heroku 发出请求时,它超时了。这是 Heroku 日志:

2021-05-15T18:33:34.397049+00:00 heroku[router]: at=info method=GET path="/login" host=aiposizi-test-api.herokuapp.com request_id=beb5b18d-9ecb-4730-b886-a5175c021377 fwd="37.214.57.227" dyno=web.1 connect=0ms service=53ms status=200 bytes=787 protocol=https
2021-05-15T18:34:10.015665+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/login" host=aiposizi-test-api.herokuapp.com request_id=f4e73df8-5116-426d-99a0-a2bfb08f3d16 fwd="37.214.57.227" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https

我的连接数据库和执行数据库查询的代码:

const {Pool} = require('pg');
const pool = new Pool({
    connectionString: process.env.DATABASE_URL,
    ssl: {
        required: true,
        rejectUnauthorized: false
    }
});

pool.query(`SELECT * FROM Users;`, (err, res) => {
    if (err) {
        console.log('Error - Failed to select all from Users');
        console.log(err);
    }
    else{
        console.log(res.rows);
    }
});

这个过程看起来像是一个无休止的数据库连接。它通过 psql 连接到 Heroku Postgre,没有任何问题。 proccess.env.DATABASE_URL 用于连接的内容 URI。我已经尝试了所有可能的连接方法 - 问题仍未解决。

0 个答案:

没有答案