Skip to content

Instantly share code, notes, and snippets.

@jpkontreras
Created September 25, 2018 11:04
Show Gist options
  • Save jpkontreras/4c9dff791c45275f40a7fefd68bc3094 to your computer and use it in GitHub Desktop.
Save jpkontreras/4c9dff791c45275f40a7fefd68bc3094 to your computer and use it in GitHub Desktop.
namespace App\Http\Middleware;
use Closure;
class CORS
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$domains = ['http://localhost:3000','https://tudominio.cl'];
if (isset($request->server()['HTTP_ORIGIN'])) {
$origin = $request->server()['HTTP_ORIGIN'];
if (in_array($origin, $domains)) {
header('Access-Control-Allow-Origin: ' . $origin);
header('Access-Control-Expose-Headers: Access-Token, Uid, filename');
header('Access-Control-Allow-Headers: Origin, Content-Type, Authorization, X-Requested-With');
}
}
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment