-3

I have created a Spring Boot Application wherein I need to consume this Web API with my client-side Angular 8 based architecture.

In modern browsers, I get CORS ISSUE WHEN I TRIED TO ACCESS THE SERVER SIDE URL DIRECTLY FROM ANGULAR APPLICATION. I am not getting like how to consume this web service when I get this error. How to get rid of Cors issue and build a production-ready code for my application with Java backend and Angular front end Application.

[EDIT] - The question might be broad but this can be termed as an knowledge perspective for people who are new to building a Java, Spring Boot and Angular Based Application.

Ashfaque Rifaye
  • 1,041
  • 3
  • 13
  • 22
  • You need to config CORS in backend response, Refer this https://stackoverflow.com/questions/46788969/angular2-spring-boot-allow-cross-origin-on-put/46789290#46789290 – hrdkisback Oct 16 '19 at 04:51
  • can you share what have you tried and what actually you need to do.. – Amrit Oct 16 '19 at 04:55

1 Answers1

0

To get around the cors issue you can publish the api to the same domain as your front end code.

/api/** your spring boot app
/** angular answers to everything else

You can setup angular-cli to proxy calls to /api/ https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/proxy.md

and then in production depending on what you are using you can do the same proxying.

Leon Radley
  • 7,596
  • 5
  • 35
  • 54