Skip to content

Instantly share code, notes, and snippets.

@feelinc
Created September 14, 2016 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feelinc/ed09e9d471e44b6ab39b30adf54c95b2 to your computer and use it in GitHub Desktop.
Save feelinc/ed09e9d471e44b6ab39b30adf54c95b2 to your computer and use it in GitHub Desktop.
CORS Middleware for Laravel
<?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