Created
July 16, 2015 19:51
-
-
Save Signorini/39c5e5af1fb7dbdaeb1c to your computer and use it in GitHub Desktop.
Middleware - Cors implemetation
This file contains 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) | |
{ | |
$config = config('cors'); | |
if($request->getMethod() == "OPTIONS") { | |
$response = new Response(); | |
foreach($config['options'] as $key => $value) | |
{ | |
$response->headers->set($key, $value); | |
} | |
return $response; | |
} | |
$content = $next($request); | |
foreach($config['outhers'] as $key => $value) | |
{ | |
$content->headers->set($key, $value); | |
} | |
return $content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment