I have been having issues connecting to my Heroku Postgres database. I've successfully run migrations on it manually, but when I try to interact with it via my app, I keep getting the same error (below)

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]:

I've double checked my config file, and it appears to be working correctly. When I log the config data, this is what I get:

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]: }

I can't figure out the root of this issue. The error logs appear to suggest that I'm trying to connect to a local db, but nowhere in my code have I prompted a connection to a local db, and since the connection info that I've passed through the Heroku config vars appears to be passing correctly, I'm at a bit of a loss as to where to look next.

For what it's worth, here is the code from my config.js, if the information is at all useful:

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 },
    }
  },
}

I should also mention that my api is working correctly - the front-end and back-end are communicating, so it's not an issue with that either.

Any help with this would be much appreciated. Thanks!

-I've double checked to make sure the issue wasn't with the api. -I've made sure the config vars were passing correctly (and that they were correct themselves). -I've sifted through my code in search of any hard-coded references to a local host and found none.

0

There are 0 best solutions below