Created
September 25, 2018 11:04
-
-
Save jpkontreras/4c9dff791c45275f40a7fefd68bc3094 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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