im currently building a REST-Api with Crow in C++ and I kinda stuck. Everything's works pretty much out of the box as expected but the POST Endpoint. Im unable to solve the CORS problem:
XMLHttpRequest cannot load http://localhost:18080/"ENDPOINT-ROUTE" due to access control checks.
http://localhost:18080/"ENDPOINT-ROUTE"
Failed to load resource: Origin http://localhost:4200 is not allowed by Access-Control-Allow-Origin.
Code:
CROW_ROUTE(app, "ENDPOINT-ROUTE").methods("POST"_method)([&app ,&m_session](const crow::request& req){
crow::response response("");
response.add_header("Access-Control-Allow-Origin", "*");
return response;
});
The request from my angular project:
create(object: Object)
{
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Access-Control-Allow-Headers':'*'
})
};
return this.http.post<Object>("http://localhost:18080/ENDPOINT-ROUTE"), object, httpOptions);
}
Thanks for your help!