Skip to content

Instantly share code, notes, and snippets.

@wayanjimmy
Created November 13, 2014 16:49
Show Gist options
  • Save wayanjimmy/bc9c3f60d04dd7aacf74 to your computer and use it in GitHub Desktop.
Save wayanjimmy/bc9c3f60d04dd7aacf74 to your computer and use it in GitHub Desktop.
Slim Middleware CORS (OPTION request intercept)
class CorsMiddleware extends \Slim\Middleware
{
public function call()
{
// Get reference to application
$app = $this->app;
if(!$app->request->isOptions()) {
// Run inner middleware and application
$this->next->call();
}
$app->response->headers->set('Access-Control-Allow-Origin', '*');
$app->response->headers->set('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
$app->response->headers->set('Access-Control-Allow-Headers', 'Origin, Content-Type, Accept');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment