Last active
September 22, 2016 14:41
-
-
Save sgorman/c402d183741c5e0634139f5781a75ad2 to your computer and use it in GitHub Desktop.
Laravel 5.3 CORS Middleware
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
| <?php | |
| namespace App\Http\Middleware; | |
| use Closure; | |
| use Illuminate\Http\Response; | |
| class CORS { | |
| /** | |
| * Handle an incoming request. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @param \Closure $next | |
| * @return mixed | |
| */ | |
| public function handle($request, Closure $next, $origin='*') | |
| { | |
| $response = $next($request); | |
| $response->headers->add([ | |
| 'Access-Control-Allow-Origin' => $origin, | |
| 'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS, PUT, DELETE', | |
| 'Access-Control-Allow-Headers' => 'Content-Type, Accept, Authorization, X-Requested-With' | |
| ]); | |
| return $response; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment