I have a Jersey REST API server, which is hit by my website(made with Angular). It is getting following client side errors
Access to XMLHttpRequest at 'http://localhost:8080/authentication/login' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I have tried adding header into response, but these are not apearing on the client side. Server side code for setting headers is implemented using filter as below
@Provider
public class CORSFilter implements javax.ws.rs.container.ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException {
response.getHeaders().add("Access-Control-Allow-Headers", "Access-Control-Allow-Origin,Content-Type");
response.getHeaders().add("Access-Control-Allow-Origin", "*");
response.getHeaders().add("Access-Control-Allow-Methods", "OPTIONS,POST");
}
}
When I check the response headers on the client side Access-Control-Allow-Origin
is missing.
A login action is taken on button press.
onLogin() {
console.log('clicked');
const url = LoginConfig.domain + '/' + LoginConfig.loginPath;
this.http.post(url, {username: 'lorem@gmail.com', secret: 'ipsum'}).subscribe(value => console.log(value.toString()));
}
I am not able to figure out what exactly is missing.