Created
September 14, 2016 12:24
-
-
Save feelinc/ed09e9d471e44b6ab39b30adf54c95b2 to your computer and use it in GitHub Desktop.
CORS Middleware for Laravel
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; | |
class CorsHeader | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @param string|null $guard | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next, $guard = null) | |
{ | |
$response = $next($request); | |
$response->headers->set('Access-Control-Allow-Origin', '*'); | |
$response->headers->set('Access-Control-Allow-Methods', 'HEAD, GET, POST, OPTIONS, PUT, PATCH, DELETE'); | |
$response->headers->set('Access-Control-Allow-Headers', 'Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Accept,Authorization'); | |
$response->headers->set('Access-Control-Expose-Headers', 'Date,Etag,Content-Type,Authorization,X-RateLimit-Limit,X-RateLimit-Remaining,X-RateLimit-Reset'); | |
return $response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment