Skip to content

Commit

Permalink
+ class App\Http\Middleware\DumpJsonResponse to dump json and show …
Browse files Browse the repository at this point in the history
…debugbar

* add `DumpJsonResponse` to middleware group `api` @ bootstrap/app.php
* add param typing in phpdoc @ `App\Http\Middleware\ReCAPTCHACheck->handle()`
@ be
  • Loading branch information
n0099 committed Jun 4, 2024
1 parent 335e607 commit 3add4c3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
25 changes: 25 additions & 0 deletions be/app/Http/Middleware/DumpJsonResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Middleware;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class DumpJsonResponse
{
/**
* @param \Closure(Request): (\Symfony\Component\HttpFoundation\Response) $next
* @source https://github.com/laravel/framework/issues/3929#issuecomment-935123918
*/
public function handle(Request $request, \Closure $next): mixed
{
$response = $next($request);
if ($response instanceof JsonResponse && $request->accepts('text/html')) {
$response->setEncodingOptions(JSON_PRETTY_PRINT);
dump($response->content());
return response('');
}

return $response;
}
}
6 changes: 5 additions & 1 deletion be/app/Http/Middleware/ReCAPTCHACheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
namespace App\Http\Middleware;

use App\Helper;
use Illuminate\Http\Request;
use ReCaptcha\ReCaptcha;
use ReCaptcha\RequestMethod\CurlPost;

class ReCAPTCHACheck
{
public function handle(\Illuminate\Http\Request $request, \Closure $next): mixed
/**
* @param \Closure(Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, \Closure $next): mixed
{
/** @var string $secret */
$secret = config('services.recaptcha.secret');
Expand Down
2 changes: 1 addition & 1 deletion be/bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
$middleware->appendToGroup('api', [\App\Http\Middleware\DumpJsonResponse::class]);
})
->withSingletons([
Illuminate\Contracts\Debug\ExceptionHandler::class => App\Exceptions\Handler::class
Expand Down

0 comments on commit 3add4c3

Please sign in to comment.