Skip to content

Instantly share code, notes, and snippets.

@feelinc
Created September 14, 2016 12:24
Show Gist options
  • Save feelinc/ed09e9d471e44b6ab39b30adf54c95b2 to your computer and use it in GitHub Desktop.
Save feelinc/ed09e9d471e44b6ab39b30adf54c95b2 to your computer and use it in GitHub Desktop.

Revisions

  1. feelinc created this gist Sep 14, 2016.
    28 changes: 28 additions & 0 deletions CorsHeader.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    <?php

    namespace App\Http\Middleware;

    use Closure;

    class CorsHeader
    {
    /**
    * Handle an incoming request.
    *
    * @param \Illuminate\Http\Request $request
    * @param \Closure $next
    * @param string|null $guard
    * @return mixed
    */
    public function handle($request, Closure $next, $guard = null)
    {
    $response = $next($request);

    $response->headers->set('Access-Control-Allow-Origin', '*');
    $response->headers->set('Access-Control-Allow-Methods', 'HEAD, GET, POST, OPTIONS, PUT, PATCH, DELETE');
    $response->headers->set('Access-Control-Allow-Headers', 'Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Accept,Authorization');
    $response->headers->set('Access-Control-Expose-Headers', 'Date,Etag,Content-Type,Authorization,X-RateLimit-Limit,X-RateLimit-Remaining,X-RateLimit-Reset');

    return $response;
    }
    }