As I understand your question, for development you are running both an API server and a UI dev server on your machine, and the UI is making calls to the API server which is running on a different port so you have to specify the host/port in the URLs. However, in production you want to not specify the host/port so it goes to the same host.
There are a couple of ways you could do this. The straight-forward way is to use environment variables in Vue. Digital Ocean actually has a guide for dealing with this exact problem:
In a web app, you will most likely have to access a backend API server through a URL. In a development environment - when you are working locally, this URL can be something like: http://localhost:8080/api. In a production environment - when the project has been deployed, this URL can be something like: https://example.com/api. Environment variables allow you to change this URL automatically, according to the current state of the project.
With Vue.js, it is possible to use environment variables through files with the .env file extension. These files are responsible for storing information that is specific to the environment (“development”, “testing”, “production”, etc.).
The other way is to try and more closely mimic your production environment. You can do that by running nginx locally on your machine, have it proxy requests something like:
- dev.example.com/api -> localhost:3001
- dev.example.com -> localhost:3000 (every other path)
Then, in your /etc/hosts file (assuming a *nix OS), point dev.example.com to 127.0.0.1 and your app + API should be reachable from the same dev.example.com address.