Home > Net >  Heroku postgres timeout and SSL issues on API calls with Node
Heroku postgres timeout and SSL issues on API calls with Node

Time:04-05

I'm trying to put my REST API built in Node and with PostgresSQL to Heroku. So, I created my application to Heroku, and created his own database. At this point, I tryied to commit, and the build worked corretly. This until I tryied to make some calls to the API. If the api calls I do has the uncorrect method, or doesn't exists, it gives me the correct error, but when the call is correct, there is a 503 error, with code H12, and description that is timeout error. Here is the code of one of the calls to the database that I'm testing:

router.get('/allpoints', async (req,res) =>{
    try {
        const points = await pool.query(
            `SELECT nome, latitudine,longitudine 
            FROM luogo`);
        res.json(points.rows);
    }catch(err){
        console.error(err.message);
    }
});

Here there are the information about how I connect to the database.

const pool = new Pool({
    connectionString: process.env.DATABASE_URL || 'postgresql://postgres:psw@localhost:5432/campione',
    ssl: process.env.DATABASE_URL ? true : false
})

module.exports = pool;

The build on Heroku seems to work properly.

I read this question: Heroku h12 Timeout Error with PG / Node.js

It says that you have to put res.end() where there is not res.json(), but here there is the res.json(). So, I thought that the issue could be that there is an error that the route manage, and can't give back anything. So, I changed from console.log(err) to res.json(err), and the API response with `ssl self signed, as an error. At this point, in the second file, I put ssl as false by default, but it gaves me error because there is no SSL. I searched for a really long time for a solution, but I have not been able yet to fix the issue.

Someone thinks he knows what should I change? Thank you in advice

CodePudding user response:

this option in databse config maybe useful

ssl: {
        rejectUnauthorized : false,
  }
  • Related