I have an Angular app on http://localhost:4200/myfrontend
that gets data from a Java REST api on http://localhost:8080/mybackend
. Within the Angular app though, every time I reach out to the REST api a new session is created.
I created a test where I put both frontend and backend on http://localhost:8080
and the session was not lost.
The settings I set for the Java REST backend are:
response.getHeaders().add("Access-Control-Allow-Origin", "*");
response.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization");
response.getHeaders().add("Access-Control-Allow-Credentials", "true");
response.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
The settings I set for the Angular 6.0.5 frontend are:
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
What must I do to keep alive the session when the frontend and backend URL are both different? Is this a missing CORS setting?