I have a macOS laptop running a application. The UI uses port 8081 and the API uses 3031. I can access this on the mac system using localhost:8081 and all of the API calls work through port localhost:3031.
The mac is on my VPN and I can ssh into it from another machine using 10.0.0.25 and I can also access the application in my browser using 10.0.0.25:8080. The problem is that the code for the application has "localhost:3031" hardcoded for the API, so even though I can see the UI in the 2nd machine, none of the API calls work because the application on the 2nd machine is sending the requests to "localhost:3031". Well, obviously this doesn't work because the 2nd machine doesn't have the API running locally.
I can't really edit the code to change it so that "localhost:3031" is no longer the hard-coded value for the API side of the application. I'm wondering what options I have to make it work so that the 2nd machine can successfully run the application and the API calls successfully send and responses are received.
I thought that maybe if I set up an nginx reverse proxy on the mac and on the 2nd machine I access 10.0.0.25:8081 in the browser and on the mac system it listens to port 8081 and proxies that traffic to localhost:8081 and then listen to port 3031 and proxy that to localhost:3031, but I get this message:
ERROR: for nginx Cannot start service nginx: Ports are not available: exposing port TCP 0.0.0.0:3031 -> 0.0.0.0:0: listen tcp 0.0.0.0:3031: bind: address already in use
Here's my nginx default.conf:
server {
listen 8080;
location / {
proxy_pass http://localhost:8081;
}
access_log /var/log/nginx/8081-access.log;
error_log /var/log/nginx/8081-error.log error;
}
server {
listen 3031;
location / {
proxy_pass http://localhost:3031;
}
access_log /var/log/nginx/3031-access.log;
error_log /var/log/nginx/3031-error.log error;
}
And the nginx docker-compose.yml file that sets up the nginx reverse proxy container:
version: '2'
services:
nginx:
image: nginx:latest
container_name: nginx
# volumes:
# - ./default.conf:/etc/nginx/conf.d/default.conf
ports:
- "8080:8081"
- "3031:3031"
Any ideas on how I can accomplish this connection with the constraints that I have? If a reverse proxy will not work, is there another method?