Which apiURL to use for production? (ECONNREFUSED 127.0.0.1:1337)

System Information
  • Strapi Version:
  • Operating System:
  • Database:
  • Node Version:
  • NPM Version:
  • Yarn Version:

Hello dear Strapi !!

I have everything setup locally and everything is working fine. I use the latest version of Gatsby and Strapi. I have successfully deployed my strapi instance on Heroku (production server running successfully) but when my Gatsby Cloud starts the build, I always get the following error:

Failed to fetch data from Strapi connect ECONNREFUSED 127.0.0.1:1337

My question is: how does my apiURL should look like in the gatsby-config.js file ? Right now it looks like this: apiURL: http://localhost:1337. I tried to change it to my heroku url: https://gatsby-strapi-heroku.herokuapp.com but then, when I run gatsby develop I get graphql errors…

So the question is: how should I specify my apiURL on my gatsby-config.js file ?

Hello guys,
I’m facing this issue when trying to deploy in production.
Does anyone know how to fix this?
Thank you!

Is your host also herokuapp.com?

Yes, the app is hosted on Heroku.
I was able to solve this problem by checking my env variables on Heroku. The project was migrated from v3.6.5 to v4.5.5 and I forgot to set a new required variable.

In your particular case it look like you need to clear the Gatsby Cloud app cache because your front-end is trying to connect to localhost (127.0.0.1:1337). I would not recommend to set your API URL directly on gatsby.config.js for security reasons, instead you could use an enviroment variable to avoid publishing sensitive information.