By neilms
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:
Frontend: http://localhost:4000/path Server: 127.0.0.1:4000
Frontend: http://127.0.0.1:4000/path Server: 127.0.0.1:4000
Frontend: http://<public-ip>:4000/path Server: 127.0.0.1:4000
Frontend: http://0.0.0.0:4000/path Server: 127.0.0.1:4000
Frontend: http://localhost:4000/path Server: 0.0.0.0:4000
Frontend: http://127.0.0.1:4000/path Server: 0.0.0.0:4000
Frontend: http://<public-ip>:4000/path Server: 0.0.0.0:4000
Frontend: http://0.0.0.0:4000/path Server: 0.0.0.0:4000
Using curl works with both http://localhost:4000/path and http://0.0.0.0:4000/path when the express server is on 127.0.0.1 or 0.0.0.0.
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!
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 127.0.0.1 port 4000, and it responds on 127.0.0.1 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:
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:
https://www.redpill-linpro.com/sysadvent/2015/12/10/introduction-to-strace.html
Jarland
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.