Created
November 13, 2014 16:49
-
-
Save wayanjimmy/bc9c3f60d04dd7aacf74 to your computer and use it in GitHub Desktop.
Slim Middleware CORS (OPTION request intercept)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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