Last active
July 3, 2019 07:38
-
-
Save jsdecena/03b723d1758e9731f71f5b8e9be0f245 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
| <?php | |
| namespace App\Http\Middleware; | |
| use Closure; | |
| use Illuminate\Http\Request; | |
| class CorsMiddleware | |
| { | |
| /** | |
| * Handle an incoming request. | |
| * | |
| * @param 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', 'POST, GET, OPTIONS, PUT, DELETE, PATCH') | |
| ->header('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With, X-XSRF-TOKEN'); | |
| } | |
| } | |
| // In App\Http\Kernel | |
| ... | |
| use App\Http\Middleware\CorsMiddleware; | |
| class Kernel extends HttpKernel | |
| { | |
| /** | |
| * The application's global HTTP middleware stack. | |
| * | |
| * These middleware are run during every request to your application. | |
| * | |
| * @var array | |
| */ | |
| protected $middleware = [ | |
| \App\Http\Middleware\CheckForMaintenanceMode::class, | |
| \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, | |
| \App\Http\Middleware\TrimStrings::class, | |
| \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, | |
| \App\Http\Middleware\TrustProxies::class, | |
| CorsMiddleware::class | |
| ]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment