提问人:Joey Fisher 提问时间:10/2/2023 更新时间:10/2/2023 访问量:75
连接到 Heroku Postgres DB 时出错:ConnectionRefusedError [SequelizeConnectionRefusedError]:连接 ECONNREFUSED 127.0.0.1:5432
Error connecting to Heroku Postgres DB: ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:5432
问:
我在连接到我的 Heroku Postgres 数据库时遇到了问题。我已经成功地手动运行了迁移,但是当我尝试通过我的应用程序与它交互时,我不断收到相同的错误(如下)
2023-10-01T19:42:49.182313+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/api/signup" host=test.fzq.io request_id=c7ddbdd8-14eb-4724-9312-a027d453bab7 fwd="80.209.137.198" dyno=web.1 connect=0ms service=83ms status=503 bytes=0 protocol=http
2023-10-01T19:52:20.599078+00:00 app[web.1]: /app/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:131
2023-10-01T19:52:20.599080+00:00 app[web.1]: reject(new sequelizeErrors.ConnectionRefusedError(err));
2023-10-01T19:52:20.599080+00:00 app[web.1]: ^
2023-10-01T19:52:20.599081+00:00 app[web.1]:
2023-10-01T19:52:20.599081+00:00 app[web.1]: ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:5432
2023-10-01T19:52:20.599119+00:00 app[web.1]: at Client._connectionCallback (/app/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:131:24)
2023-10-01T19:52:20.599252+00:00 app[web.1]: at Client._handleErrorWhileConnecting (/app/node_modules/pg/lib/client.js:327:19)
2023-10-01T19:52:20.599252+00:00 app[web.1]: at Client._handleErrorEvent (/app/node_modules/pg/lib/client.js:337:19)
2023-10-01T19:52:20.599253+00:00 app[web.1]: at Connection.emit (node:events:517:28)
2023-10-01T19:52:20.599253+00:00 app[web.1]: at Socket.reportStreamError (/app/node_modules/pg/lib/connection.js:58:12)
2023-10-01T19:52:20.599253+00:00 app[web.1]: at Socket.emit (node:events:517:28)
2023-10-01T19:52:20.599255+00:00 app[web.1]: at emitErrorNT (node:internal/streams/destroy:151:8)
2023-10-01T19:52:20.599255+00:00 app[web.1]: at emitErrorCloseNT (node:internal/streams/destroy:116:3)
2023-10-01T19:52:20.599256+00:00 app[web.1]: at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
2023-10-01T19:52:20.599256+00:00 app[web.1]: parent: Error: connect ECONNREFUSED 127.0.0.1:5432
2023-10-01T19:52:20.599256+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
2023-10-01T19:52:20.599257+00:00 app[web.1]: errno: -111,
2023-10-01T19:52:20.599257+00:00 app[web.1]: code: 'ECONNREFUSED',
2023-10-01T19:52:20.599258+00:00 app[web.1]: syscall: 'connect',
2023-10-01T19:52:20.599258+00:00 app[web.1]: address: '127.0.0.1',
2023-10-01T19:52:20.599258+00:00 app[web.1]: port: 5432
2023-10-01T19:52:20.599259+00:00 app[web.1]: },
2023-10-01T19:52:20.599259+00:00 app[web.1]: original: Error: connect ECONNREFUSED 127.0.0.1:5432
2023-10-01T19:52:20.599259+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
2023-10-01T19:52:20.599259+00:00 app[web.1]: errno: -111,
2023-10-01T19:52:20.599260+00:00 app[web.1]: code: 'ECONNREFUSED',
2023-10-01T19:52:20.599260+00:00 app[web.1]: syscall: 'connect',
2023-10-01T19:52:20.599260+00:00 app[web.1]: address: '127.0.0.1',
2023-10-01T19:52:20.599260+00:00 app[web.1]: port: 5432
2023-10-01T19:52:20.599261+00:00 app[web.1]: }
2023-10-01T19:52:20.599261+00:00 app[web.1]: }
2023-10-01T19:52:20.599261+00:00 app[web.1]:
我已经仔细检查了我的配置文件,它似乎工作正常。当我记录配置数据时,我得到的是:
2023-10-01T19:42:42.373934+00:00 app[web.1]: Config {
2023-10-01T19:42:42.373962+00:00 app[web.1]: url: '<correct connectionString>',
2023-10-01T19:42:42.373966+00:00 app[web.1]: database: '<correct db name>',
2023-10-01T19:42:42.373967+00:00 app[web.1]: username: '<correct username>',
2023-10-01T19:42:42.373971+00:00 app[web.1]: password: '<correct password>',
2023-10-01T19:42:42.373972+00:00 app[web.1]: dialect: 'postgres',
2023-10-01T19:42:42.373972+00:00 app[web.1]: dialectOptions: { ssl: { require: true, rejectUnauthorized: false } }
2023-10-01T19:42:42.373973+00:00 app[web.1]: }
我无法弄清楚这个问题的根源。错误日志似乎表明我正在尝试连接到本地数据库,但是在我的代码中没有任何地方提示连接到本地数据库,并且由于我通过 Heroku 配置 vars 传递的连接信息似乎正确传递,我对下一步该看的地方有点茫然。
就其价值而言,如果信息有用,这是我的 config.js 中的代码:
module.exports = {
development: {
url: process.env.DATABASE_URL,
database: process.env.DATABASE,
username: process.env.USERNAME,
password: process.env.PASSWORD,
dialect: 'postgres',
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false },
}
},
test: {
url: process.env.DATABASE_URL,
database: process.env.DATABASE,
username: process.env.USERNAME,
password: process.env.PASSWORD,
dialect: 'postgres',
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false },
}
},
production: {
url: process.env.DATABASE_URL,
database: process.env.DATABASE,
username: process.env.USERNAME,
password: process.env.PASSWORD,
dialect: 'postgres',
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false },
}
},
}
我还应该提到我的 api 工作正常 - 前端和后端正在通信,所以这也不是问题。
任何帮助将不胜感激。谢谢!
- 我已经仔细检查以确保问题不出在 api 上。 -我已经确保配置变量正确传递(并且它们本身是正确的)。 - 我已经筛选了我的代码以查找对本地主机的任何硬编码引用,但没有找到。
答: 暂无答案
评论