Home  >  Forum  >  Angular
Post New Query

How to handle CORS in angular?



Asked on May 08, 2018
Hello,

I am using spring boot micro service with angular application. And I am using UAA as authorization server. If session expires means the application should show the message in pop up and should redirect to login page. How to achieve this in angular?

Can any one provide solution in this?

Thanks and Regards
Shilpa Kulkarni  



Replied on May 08, 2018
If session expired means in the console it is trying to redirect to login page but the cross-origin request is blocking .
 I am getting the following error: 

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at localhost:8081/uaa/oauth/…. (Reason: CORS preflight channel did not succeed)

How to resolve this?



Replied on May 09, 2018
You need to allow cross-origin request. Use @CrossOrigin at server side controller and configure client domains. For example.  

@Controller
@CrossOrigin(origins = {"http://localhost:8081", "http://localhost:8088"})
public class MyController {

}

Find the link to understand CORS




Replied on May 14, 2018
Thank you. It worked. 


Write Answer




©2019 concretepage.com | Privacy Policy | Contact Us