Cleanup
This commit is contained in:
1 parent
b53047a28c
commit
42404cc2cc
9 files changed
+79
-136
No files matched your search
+2
-28
@@ -4,32 +4,6 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use MattitjaAB\LaravelPlausibleProxy\Http\Controllers\PlausibleEventApiController;
|
||||
|
||||
Route::post('api/event', function (Request $request) {
|
||||
$data = json_decode($request->getContent(), true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
return response()->json(['error' => 'Invalid JSON format'], 422);
|
||||
}
|
||||
|
||||
$validator = Validator::make($data, [
|
||||
'n' => 'required|string',
|
||||
'u' => 'required|url',
|
||||
'd' => 'required|string',
|
||||
'r' => 'nullable|url',
|
||||
'm' => 'nullable|string',
|
||||
'p' => 'nullable|array',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['status' => 'error', 'errors' => $validator->errors()], 422);
|
||||
}
|
||||
|
||||
$headers = collect($request->headers->all())
|
||||
->mapWithKeys(fn ($value, $key) => [$key => is_array($value) ? implode(', ', $value) : $value])
|
||||
->all();
|
||||
|
||||
Http::withHeaders($headers)->post(config('plausible-proxy.domain').'/api/event', $data);
|
||||
|
||||
return response()->json(['status' => 'queued']);
|
||||
});
|
||||
Route::post('api/event', PlausibleEventApiController::class);
|
||||
Reference in new issue
Block a user