Skip to content

Instantly share code, notes, and snippets.

@ADmad
Last active November 3, 2017 19:27
Show Gist options
  • Save ADmad/8547377 to your computer and use it in GitHub Desktop.
Save ADmad/8547377 to your computer and use it in GitHub Desktop.
<?php
App::uses('DispatcherFilter', 'Routing');
class CorsFilter extends DispatcherFilter {
public function beforeDispatch(CakeEvent $event) {
if ($event->data['request']->is('OPTIONS')) {
$event->stopPropagation();
$event->data['response']->header(array(
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'POST, PUT, DELETE, GET, HEAD',
'Access-Control-Allow-Headers' => 'Origin, X-Requested-With, Content-Type, Authorization'
));
return $event->data['response'];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment