0

I have Spring boot and Angular app in Tomcat Container deployed on Server. It works totally fine on localhost.

Now I am trying to map my domain with the application.

When I call my domain then API calls from Angular to Spring are not getting executed.
Since they are on same server I use localhost to call the API from angular to spring.
Which works on my server browser itself but not somewhere else which is clear to me why it's not working.

But I am not totally sure how to go around it.

API call Here is my nginx configuration:

   server {
        listen       80;
        server_name localhost mydomain mydomain;

        
        #access_log  logs/host.access.log  main;

        location {
            root   html;
         proxy_pass      http://mydomain:8080;
            index  index.html index.htm;
        }       
    }

Tomcat configuration:

 <Host name="mydomain"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
        <Alias>mydomain</Alias>
        <Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />   
</Host>

My questions are:

  • Should I use the Server IP while calling the API from Angular to Spring? Will it work?

  • Second question is when I call my domain it redirects to tomcat manager page. I want it to go to localhost:8080/myApp.

I tried proxy_pass as http://mydomain:8080/myapp & http://localhost:8080/myapp but still no success.

Any pointers for both of these questions would be highly appreciated.
I am available here for any information.

Gryu
  • 479
  • 1
  • 6
  • 14
lesnar
  • 101
  • 1

1 Answers1

1

The URL your Angular app uses to call the API should be configurable or automatically detected. So you can use:

  1. the JavaScript global location object or
  2. a similar object on the server side, like HttpServletRequest#getRequestURL(), which you'll have to send to the Angular app (e.g. in a <script> tag).

Using the server's IP address is tolerable, but a better solution is to use a domain name, which points at that address.

Your Tomcat installation probably has a ROOT application, which redirects to the Tomcat Manager app. You should empty it if you don't use it (delete all files, keep the directory).

,

Piotr P. Karwasz
  • 5,292
  • 2
  • 9
  • 20