Add middleware to set Content-type to application/json on all API requests
This commit is contained in:
parent
d04c11f660
commit
a5c5518a12
@ -37,6 +37,7 @@ class Kernel extends HttpKernel
|
|||||||
'api' => [
|
'api' => [
|
||||||
'throttle:60,1',
|
'throttle:60,1',
|
||||||
'bindings',
|
'bindings',
|
||||||
|
'json',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -54,6 +55,7 @@ class Kernel extends HttpKernel
|
|||||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||||
|
'json' => \App\Http\Middleware\JsonResponse::class,
|
||||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||||
#'role' => \Laratrust\Middleware\LaratrustRole::class,
|
#'role' => \Laratrust\Middleware\LaratrustRole::class,
|
||||||
#'permission' => \Laratrust\Middleware\LaratrustPermission::class,
|
#'permission' => \Laratrust\Middleware\LaratrustPermission::class,
|
||||||
|
18
app/Http/Middleware/JsonResponse.php
Normal file
18
app/Http/Middleware/JsonResponse.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Set the content type in the API layer
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
|
||||||
|
class JsonResponse
|
||||||
|
{
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
$response = $next($request);
|
||||||
|
$response->headers->set('Content-Type', 'application/json');
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user