• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

A Problem while deploying Spring Boot + Angular application

 
Ranch Hand
Posts: 37
Python Angular Framework Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

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

Unfortunately, I am not seeing my Angular app, what I am seeing is the "Whitelabel Error Page"

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.

But 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?

My App has two controllers (@RestController) , that have a couple of GET\POST\DELETE\PUT requests.

And I configured a JWTAuthenticationFilter and 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.

Can you please help me fix this issue, or guide me where can I find an explaination about this ?
 
Rancher
Posts: 506
6
IntelliJ IDE Spring Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you bundle the angular app with the spring boot app you would want to put some execution info in maven pom file.

If the angular app is just hanging out in the static area you would need to make the url path to your static files accessible without logging in.
 
Redan Hassoun
Ranch Hand
Posts: 37
Python Angular Framework Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Al Hobbs wrote:if you bundle the angular app with the spring boot app you would want to put some execution info in maven pom file.

If the angular app is just hanging out in the static area you would need to make the url path to your static files accessible without logging in.



Hi,
Yes you are right, I need to make the URL path to the static files accessible without logging in. And I found the way to do it:

The problem was that all the requests were authenticated in the "WebSecurityConfigurerAdapter":



So I had to replace the ".anyRequest().authenticated()" with ".antMatchers( "/api/**").authenticated()" in order to authenticate only the API (all of my API requests starts with /api/v1/).


Thanks.
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!