Created
June 15, 2018 21:01
-
-
Save danilodorgam/363dd15d2a3676e6161bca1b0d2417dd to your computer and use it in GitHub Desktop.
Script para liberar acesso via API por outros domínio (Liberar o Cors)
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
//app/Http/Middleware/EnableCors.php | |
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
class EnableCors | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
$response = $next($request); | |
$response->headers->set('Access-Control-Allow-Origin', '*'); | |
$response->headers->set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE, PATCH'); | |
$response->headers->set('Access-Control-Allow-Headers', 'Content-Type, origin, Accept, Authorization, X-Requested-With, Application'); | |
return $response; | |
} | |
} |
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
//Http/Kernel.php | |
<?php | |
... | |
protected $middleware = [ | |
... | |
\App\Http\Middleware\EnableCors::class, | |
]; | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment