Implement webhook inspector

This commit is contained in:
2026-08-04 17:09:39 +02:00
parent b021836c14
commit 75d8b25b64
57 changed files with 5110 additions and 230 deletions
@@ -0,0 +1,56 @@
<?php
namespace App\Http\Controllers;
use App\Actions\CaptureWebhookRequestAction;
use App\Actions\CreateAnonymousEndpointAction;
use App\Models\WebhookEndpoint;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Gate;
class EndpointController extends Controller
{
public function storeAnonymous(CreateAnonymousEndpointAction $createAnonymousEndpoint): RedirectResponse
{
$endpoint = $createAnonymousEndpoint->handle();
return redirect()->route('inspect.show', ['token' => $endpoint->token]);
}
public function receive(
Request $request,
string $token,
CaptureWebhookRequestAction $captureWebhookRequest,
): Response|JsonResponse {
$endpoint = WebhookEndpoint::findByToken($token);
abort_unless($endpoint instanceof WebhookEndpoint && $endpoint->acceptsRequests(), 404);
if (strlen($request->getContent()) > (int) config('webhooks.max_body_bytes', 1024 * 1024)) {
return response()->json(['message' => 'The webhook request body is too large.'], 413);
}
$captureWebhookRequest->handle($endpoint, $request);
$endpoint->refresh();
return response(
$endpoint->response_body ?? '{}',
$endpoint->response_status,
$endpoint->response_headers ?? ['Content-Type' => 'application/json'],
);
}
public function destroy(string $token): RedirectResponse
{
$endpoint = WebhookEndpoint::findByToken($token);
abort_unless($endpoint instanceof WebhookEndpoint, 404);
Gate::authorize('delete', $endpoint);
$endpoint->delete();
return redirect()->route('home')->with('status', 'Endpoint deleted.');
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers;
use App\Models\WebhookEndpoint;
use Illuminate\Support\Facades\Gate;
use Illuminate\View\View;
class InspectorController extends Controller
{
public function show(string $token): View
{
$endpoint = WebhookEndpoint::findByToken($token);
abort_unless($endpoint instanceof WebhookEndpoint && $endpoint->acceptsRequests(), 404);
Gate::authorize('view', $endpoint);
return view('inspector-page', ['endpoint' => $endpoint]);
}
}