snelg / cakephp-cors

CORS plugin for CakePHP 3
19 stars 2 forks source link

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

Open dipeshcct opened 7 years ago

dipeshcct commented 7 years ago

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] ]]);

snelg commented 7 years ago

Which version of CakePHP are you using?

LeWestopher commented 7 years ago

@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');