How can I get a vue application to talk an express api on my droplet?

On my local I just run the express app on localhost port 4000 and my vue app can connect using axios to localhost:4000/api/myendpoint.

On the droplet I built the vue app into a static dist folder and set it up with nginx and I have the express app running on localhost port 4000. So, now the frontend is properly displayed, but when it tries to make an api call to the express app I get “net::ERR_CONNECTION_REFUSED”.

Here are the configurations I’ve tried:

Using curl works with both http://localhost:4000/path and when the express server is on or

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hey friend,

Interesting problem. Though things can be more complex, they rarely are. I like to take a step back and think of something so crazy simple that we’d usually look well past it. If the app on the server is listening on port 4000, and it responds on port 4000 to a local curl request, while the app receives a “Connection Refused” error, then I propose that the app is not trying to connect locally to the internal IP/port.

The reason I arrive there is that my other ideas fall short quickly:

  1. Firewall. If you can curl it, the firewall setting to block the app but not yourself is far too complex to have accidentally bumped into it (UID blocking I’m thinking, never seen it by accident).
  2. Linux user account lacking ability to make connection. I don’t even know how to do this, I just assume it’s theoretically possible. My lack of knowledge of how to do it is a testament to the fact that I’ve never witnessed it.

This leads me to what I think is the simplest answer, that the app isn’t doing what you think it’s doing. I could be wrong, it’s just where my mind keeps going. If you can grab the process ID of the app running when it processes the request, then you can try an strace to really see exactly what it’s doing. I really like this article for learning how to use/read strace: