使用 Angular 前端和 Spring Boot 后端处理 IP 与域名请求

问题描述 投票:0回答:1

我正在开发一个带有 Angular 前端的 Spring Boot 应用程序,该前端充当基本的登录门户。登录门户使用加密凭据并单击验证来验证用户身份。我的目标是根据用户是通过服务器的 IP 地址还是域名访问应用程序来区分行为。 所需功能:

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.

我做了什么:

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.

关键问题:

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?

附加信息:

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.).

任何有关如何解决此问题的指导或建议将不胜感激!

java html angular server angular-fullstack
1个回答
0
投票

好的,所以我找到了我正在寻找的答案是通过代理,您可以从此解决方案中的答案中获取域名。看来我在这种情况下正在寻找的是 Angular 文档here中定义的代理。一旦你将这两个放在一起,你就可以将基本 URL 或实际上整个 URL 返回到 Spring Boot 后端来请求所请求的资源,但是通过使用代理,似乎不需要这,只需要后端能够在请求重定向到后端时处理请求,然后将请求传递回前端以供客户端组合在一起。构建一个 httpserver 是通过使用这个类完成的,并且可以与其他一些类相结合,以实际将请求返回给角度应用程序,然后返回给客户端。

© www.soinside.com 2019 - 2024. All rights reserved.