Skip to content

Instantly share code, notes, and snippets.

@amitkhare
Created December 10, 2017 11:30
Show Gist options
  • Save amitkhare/d258b8bf3b5c789400abd3ec6d6d82b6 to your computer and use it in GitHub Desktop.
Save amitkhare/d258b8bf3b5c789400abd3ec6d6d82b6 to your computer and use it in GitHub Desktop.
<?php
// Application middleware
// e.g: $app->add(new \Slim\Csrf\Guard);
// A middleware for enabling CORS
$app->add(function ($req, $res, $next) {
$response = $next($req, $res);
return $response
->withHeader('Access-Control-Allow-Origin', '*')
->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization')
->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment