On WebSphere Liberty I have a back end that run on https://localhost:9443/context-root/objects. It works and i can test my REST APIs from a browser or postman.
I coded a Web UI in Angular with Visual Studio Code. When i try to test ('> ng serve') with Crome localhost:4200 with the UI http calls of the REST API i get errors:
server.xml without CORS settings
The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:4200' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
Response Headers
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:origin, content-type, accept, authorization
Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS, HEAD
Access-Control-Allow-Origin:*
Access_Control_Max_Age:43200
Cache-Control:no-store, no-cache=set-cookie
Content-Length:284
Content-Type:application/json
server.xml with CORS settings
<cors domain="/context-root" allowedOrigins="http://localhost:4200" allowedMethods="GET, DELETE, POST, PUT" allowedHeaders="accept" allowCredentials="true" maxAge="3600" />
Error:
Failed to load https://localhost:9443/context-root/objects: The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:4200, *', but only one is allowed. Origin 'http://localhost:4200' is therefore not allowed access.
Response headers:
Access-Control-Allow-Credentials:true
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:origin, content-type, accept, authorization
Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS, HEAD
Access-Control-Allow-Origin:http://localhost:4200
Access-Control-Allow-Origin:*
Access_Control_Max_Age:43200
I am not sure why i get double values in the Response Headers and why in particular i get 2 allow-origin. Is there a way around this? thanks