0

For context, I am using the reactjs gatsby framework which provides a plugin to connect to a strapi backend. When specifying the strapi api url as "localhost", it throws an error "econnrefused". Yet, when using "127.0.0.1", the error is resolved. I know localhost and 127.0.0.1 are not exactly the same, but I'd like to know some possible reasons why this might be occurring (full disclosure: beginner level here).

p.s. documentation says to use "localhost" which is throwing the error for me.

Thanks so much!

Summary: following the gatsby-source-strapi plugin instructions, I specified "localhost" as the strapi api url (localhost:1337). When starting up the local development server (localhost:8000), the "econnrefused" error would be thrown by the plugin. However, when "127.0.0.1" (which localhost is an alias for) was used, the error would be resolved.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
ahpto
  • 11
  • 5
  • What about `http://localhost:1337`? – Konrad Nov 08 '22 at 19:02
  • Could be a CORS issue. – Tim Nov 08 '22 at 19:04
  • sorry, when I said "localhost" it was just short for http://localhost:1337 – ahpto Nov 08 '22 at 19:14
  • MDN web docs: "For security reasons, browsers restrict cross-origin HTTP requests initiated from scripts [...] This means that a web application using those APIs can only request resources from the same origin the application was loaded from unless the response from other origins includes the right CORS headers" -so perhaps localhost and 127.0.0.1 are somehow being seen as different sources? – ahpto Nov 08 '22 at 19:22

0 Answers0