简体   繁体   English

部署 Spring Boot + Angular 应用程序时出现问题

[英]A Problem while deploying Spring Boot + Angular application

I created an Angular application with a Spring Boot backend, currently I work locally by running the server on Intellij and the angular App with "ng serve", I want to deploy my app to Heroku. I created an Angular application with a Spring Boot backend, currently I work locally by running the server on Intellij and the angular App with "ng serve", I want to deploy my app to Heroku.

I searched on the internet, and I saw that one of the first steps to do that is to build the Angular app and copy the "dist" content to "src/main/resources/static".我在互联网上搜索,我看到这样做的第一步是构建 Angular 应用程序并将“dist”内容复制到“src/main/resources/static”。

I copied the content, then tried to run the server (still working locally) and access the app from the browser at this address: " http://localhost:3000/ " (I defined 3000 as the Spring Boot app port).我复制了内容,然后尝试运行服务器(仍在本地工作)并从浏览器访问该地址的应用程序:“ http://localhost:3000/ ”(我将 3000 定义为 Spring 启动应用程序端口)。

Unfortunately, I am not seeing my Angular app, what I am seeing is the "Whitelabel Error Page"不幸的是,我没有看到我的 Angular 应用程序,我看到的是“Whitelabel 错误页面”

 This application has no explicit mapping for /error, so you are seeing this as a fallback. Sat Nov 09 17:26:21 IST 2019 There was an unexpected error (type=Forbidden, status=403). Access Denied

I assume that I am getting "access denied" error because I have a "JWTAuthorizationFilter" on my API - consumers of the API must provide a valid JSON web token in the request header. I assume that I am getting "access denied" error because I have a "JWTAuthorizationFilter" on my API - consumers of the API must provide a valid JSON web token in the request header.

My question is: What should I do in order to cause the " http://localhost:3000/ " return the Angular App and not access the API, what am I missing here?我的问题是:我应该怎么做才能导致“ http://localhost:3000/ ”返回 Angular 应用程序而不访问 API,我在这里缺少什么?

My App has two controllers (@RestController), that have a couple of GET\POST\DELETE\PUT requests.我的应用程序有两个控制器 (@RestController),它们有几个 GET\POST\DELETE\PUT 请求。

And I configured a JWTAuthenticationFilter and JWTAuthorizationFilter.我配置了一个 JWTAuthenticationFilter 和 JWTAuthorizationFilter。

I still don't understand how the separation between the angular application and the Spring Rest API is expressed in the Java spring project deployment. I still don't understand how the separation between the angular application and the Spring Rest API is expressed in the Java spring project deployment.

Can you please help me fix this issue, or guide me where can I find an explanation about this?你能帮我解决这个问题吗,或者指导我在哪里可以找到关于这个的解释?

What you are trying to do is to serve the Angular App from the spring boot tomcat embedded servlet container, therefore the security configuration affects the endpoints where the static angular files are. What you are trying to do is to serve the Angular App from the spring boot tomcat embedded servlet container, therefore the security configuration affects the endpoints where the static angular files are.

To solve your problem, in your security configuration class (class extending WebSecurityConfigurerAdapter) you could only restrict your actual api endpoints, for example:为了解决您的问题,在您的安全配置 class(扩展 WebSecurityConfigurerAdapter 的类)中,您只能限制您的实际 api 端点,例如:

http.authorizeRequests().antMatchers( "/api/**").authenticated();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM