-
-
Save jjcodes78/090971a887616f08645e063df590bc07 to your computer and use it in GitHub Desktop.
CORS middleware example
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
<?php | |
namespace App\Http\Middleware; | |
class HandleCorsMiddleware | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
$response = $next($request) | |
->header('Access-Control-Allow-Origin', 'http://example.com/') // * = any origin | |
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS') // * = any method | |
->header('Access-Control-Allow-Headers', 'Content-Type, X-Requested-With') // * = any header | |
->header('Access-Control-Allow-Credentials', 'true'); | |
return $response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment