Hi All,
I’m having trouble using Cakephp as a REST API server for an Angular application.
I’m using cakephp 4.1.5.
If i put this headers in bootstrap.php file the apis call responds without problems:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, PUT, PATCH, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: *');
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
exit(0);
}
But this isn’t a solution that i can manage in production.
So I’m trying with https://github.com/ozee31/cakephp-cors
that can’t manage the OPTION and seem not working.
Reading the documentation https://book.cakephp.org/4/en/controllers/request-response.html#setting-cross-origin-request-headers-cors
i can’t understand how to make this work for all the REST API application.
I’m stuck in the problem with a lot of confusion, can someone help me to find a way?