I am trying to get a new app set up on fly.io. This is my first time working with Fly. I have an app that has been deployed on Heroku that needs a new home. It is a Node.js REST API with a postgres database. It also has a React frontend that needs a new home and would love to have it all in one place, but for now, I’m focused on getting the backend up and running.
I have followed the instructions for flyctl launch
. It successfully detects my app as Node, prompts to set up the postgres db, it claims to be properly attached, I add my other secrets and deploy. Each time, it successfully deploys the backend but the backend is unable to communicate with the database. If I go to backend root, I get the 200 success response. But if I try to hit any of the query endpoints that talk to postgres, I get connect ECONNREFUSED 127.0.0.1:5432'
.
I can successfully connect to the postgres db from the CLI with flyctl postgres connect -a recipes-api-db
. I am able to get into the psql CLI and create all my tables and see that succeed, but nothing seems to enable the connection between the deployed API and the db.
In reading through similar posts, I haven’t really seen much else actionable. Most people who complained of similar issues went through a handful of debugging steps to check the IPs, but ultimately if the problem was resolved they just said “I deleted and started again a few times and it finally worked.” I have deleted both apps and started from scratch four or five times now with no success.
I am using the fly.toml
that was created automatically. The only change I have made is to add private_network = true
under experimental as I’ve seen suggested, but that doesn’t seem to make any difference.
I do also notice that the postgres app does not automatically assign any IP addresses. It says I can assign them myself, but I wouldn’t know what values to choose. Is this something I need to do?
I am working from a MacOS computer.
Any help you can provide to guide me through what steps I may have missed would be greatly appreciated!!
Also, as a side note, after the first failed attempt, I saw you had the heroku conversion option. I tried that and after just a few clicks, I successfully had a new backend deployed in Fly that seems to work perfectly. I have already changed my heroku deployed frontend to point to this new Fly backend. However, as far as I can tell, this is still directly connected to heroku, with the postgres db still living on Heroku. And that db will be deleted by Heroku in a few months, so unless I’m misunderstanding the connection, this is not a viable solution for me. Once I get this working the correct way, I will need to delete that app.