KB81
KB81

Reputation: 1

CORS validation with Angular app and Rest services in Azure

We are working in the cloud, with Azure, where we have 3 segments: one for front (angular) one for back (java) and the last one for data. Currently, we are facing an issue that didn’t let us connect the angular with java code. We are having a CORS validation for the Angular app and Rest services communication. This issue is only happening in the cloud but not in our local setup.

Error message:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://crecemasbcpdesa.lima.bcp.com.pe' is therefore not allowed access. The response had HTTP status code 504.

Upvotes: 0

Views: 213

Answers (1)

assylias
assylias

Reputation: 328608

Have you enabled CORS support in your Java EE app? Something like:

@Provider
public class CORSResponseFilter implements ContainerResponseFilter {

  @Override
  public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) throws IOException {
    MultivaluedMap<String, Object> headers = containerResponseContext.getHeaders();

    headers.add("Access-Control-Allow-Origin", "*");
    headers.add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
    headers.add("Access-Control-Allow-Headers", "Content-Type");
  }
}

Upvotes: 2

Related Questions