0

I have a war file with spring boot as server side and angular 8 as front end.

and the war is getting deployed in remote machine where ip changes on restart.

If I deploy the war where rest request call from angular are made with ip address of the host it was working fine

http://54.172.42.170:8080/test/getMessage 

since the IP is changing on each time machine restart i need to change the code each time

Is there a way where i can make the rest call with out referring ip address, as both angular and spring boot are packaged in same war

i tried using local host in the rest url , but getting error

ERR_CONNECTION_REFUSED 

it was working only when war is deployed in my desktop not on remote machine, which makes sense.

Adding Client Code:

 public SERVER_IP:string="54.172.42.170"; public SERVER_PORT:string="8080"; public SERVER_PROTOCOL:string="http"; public APP_CONTEXT:string="test"; public URL_BASE:string= this.SERVER_PROTOCOL+"://"+this.SERVER_IP+":"+this.SERVER_PORT+"/"+ this.APP_CONTEXT+"/"; public URL_GET_MESSAGE:string= this.URL_BASE +"getMessage"; this.http.get(this.constant.URL_GET_MESSAGE,{params: data}) 
2
  • can you post your client code? How you're making call? You can possibly do relative URL. Commented Sep 14, 2019 at 2:13
  • It's related to network configuration either you can bind your instance to 127.0.0.1 or use static IP so that your ip won't change every time you restart you machine. Configure your tomcat to bind to 127.0.0.1. Commented Sep 14, 2019 at 2:16

2 Answers 2

2

Yes there is a pretty simple way to implement this. When you build your application, set your SERVER_IP parameter to "/". This simple forward slash means that if your angular application loads on xyz.com then your API url will be xyz.com.

Also you can then form the URL using the code:

public URL_BASE:string= "/"+ this.APP_CONTEXT+"/"; 

Of course, you'll need to get rid of Port by using a reverse proxy like NGINX.

Thus, it will always be relative to your current host URL. This is an approach we use in multiple of our applications and it works smooth.

Sign up to request clarification or add additional context in comments.

Comments

0

Either u fixed the remote machine ip permanently neither you will do the testing in your local machine it will work.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.