cakephp-cors icon indicating copy to clipboard operation
cakephp-cors copied to clipboard

Getting No 'Access-Control-Allow-Origin' error

Open dipeshcct opened this issue 7 years ago • 2 comments

I have used this plugin as per described step. But when I try to execute, I getting an error "Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource" I have used below code for the same $routes->connect('/authenticate', ['controller' => 'Users', 'action' => 'login', 'cors' => [ 'origin' => 'https://UI_PART_URL', 'methods' => ['POST'], 'headers' => ['Access-Control-Allow-Credentials' => true] ]]);

dipeshcct avatar Jul 25 '17 07:07 dipeshcct

Which version of CakePHP are you using?

snelg avatar Jul 26 '17 15:07 snelg

@dipeshcct Are you loading the CorsFilter class using the DispatchFactory::add() method prior to defining the CORS options on your routes? The CorsFilter needs to be loaded in bootstrap.php regardless of whether your CORS configuration is defined on your routes or your DispatchFactory::add() configuration array. Check bootstrap.php and ensure that the following line exists:

DispatcherFactory::add('Cors.Cors');

LeWestopher avatar Aug 01 '17 13:08 LeWestopher