javahtmlangularserverangular-fullstack

Handling IP vs. Domain Name Requests with Angular Frontend and Spring Boot Backend


I'm working on a Spring Boot application with an Angular frontend that serves as a basic login portal. The login portal uses encrypted credentials and click verification to authenticate users. My goal is to differentiate behavior based on whether the user accesses the application via the server's IP address or a domain name. Desired Functionality:

When accessing the server via its IP address (e.g., 0.0.0.0:8080): Users should be directed to the Angular login page. Once authenticated, they would have access to a control panel for managing server settings (IPs, files, etc.).
When accessing the server via a domain name (e.g., example.com:8080): The server should serve a different website (an index.html or multi-page site) rather than the Angular control panel.

What I’ve Done:

I know how to handle HTTP requests in Java with Spring Boot and how to serve the Angular frontend as a static resource. However, I’m unsure how to programmatically differentiate requests based on whether the user is accessing the site by IP or domain name and serve different content accordingly.

Key Questions:

How can I configure my Spring Boot application to detect whether the user is accessing via IP address or domain name and serve different content?
Should this logic reside in Java (Spring Boot) or should Angular handle the request and pass the URL to the backend for processing?
Are there specific libraries, configurations, or strategies I can use to achieve this, particularly when dealing with both Angular and static HTML pages in the same application?

Additional Information:

The application is similar to Webmin, Plesk, or cPanel, where the control panel is accessed via IP while a public-facing website is served when a domain is used.
The Angular front end is primarily for server management (changing files, updating emails, etc.).

Any guidance or suggestions on how to approach this would be greatly appreciated!


Solution

  • Ok, so I have found the answer I am looking for is through a proxy, you can get the domain name from the answer in this solution. It seems that what I was looking for in this case is a proxy which is defined in Angular's Documentation here. Once you have these two put together, you can then pass the base URL or really the Entire URL Back to the Spring Boot backend to request the requested resource, however by using the proxy it seems this would not be needed and would just need the Backend to be able to handle requests as they are redirected to the Backend, which would then be passed back to the front end to put together for the client. building an httpserver is done by using this class and can be combined with some others to actually give the requests back to the angular application to then give back to the client.