jonnybarnes.uk/app/Http/Middleware/CorsHeaders.php
Jonny Barnes c52f0e17d7 Add CORS headers to the media endpoint
Squashed commit of the following:

commit 0a620148dfad998f7b00804cae1db8208b23cc02
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Fri Mar 2 15:08:36 2018 +0000

    Add tests for the Cors Headers

commit dd8518d279cdf3857597fa7ee6150bf383203fe1
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Fri Mar 2 15:08:20 2018 +0000

    Only add Cors Headers to requests to the media endpoint

commit 6c79ca5632581345ef406f211b1576a4b7f400fe
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Fri Mar 2 15:07:53 2018 +0000

    Add CorsHeaders to middleware array

commit e12d48ca1e837b14b75bbd87d6197d59d60cf32e
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Fri Mar 2 15:06:32 2018 +0000

    We need to send something to the OPTIONS request to the media endpoint

commit f11c638be464373bff09bf015d4a989e48e61f0c
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Fri Mar 2 15:05:45 2018 +0000

    Change routes to allow for responses to an OPTIONS request to the media endpoint
2018-03-02 15:49:07 +00:00

28 lines
774 B
PHP

<?php
namespace App\Http\Middleware;
use Closure;
class CorsHeaders
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
if ($request->path() === 'api/media') {
$response->header('Access-Control-Allow-Origin', '*');
$response->header('Access-Control-Allow-Methods', 'OPTIONS, POST');
$response->header('Access-Control-Allow-Headers', 'Authorization, Content-Type, DNT, X-CSRF-TOKEN, X-REQUESTED-WITH');
$response->header('Access-Control-Allow-Credentials', 'true');
}
return $response;
}
}