Question
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::ERRCONNECTIONREFUSED”.
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.
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.
×