Skip to content

Instantly share code, notes, and snippets.

@cuonghuynh
Last active November 22, 2016 03:17
Show Gist options
  • Save cuonghuynh/9fbdcf13bdea96e06d768019d454cad0 to your computer and use it in GitHub Desktop.
Save cuonghuynh/9fbdcf13bdea96e06d768019d454cad0 to your computer and use it in GitHub Desktop.
Setup CORS for your api
//app\Http\Middleware\Cors.php
<?php
namespace App\Http\Middleware;
use Closure;
class CorsMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', '*')
->header('Access-Control-Expose-Headers', 'authorization');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment