diff --git a/app/Http/Controllers/HealthController.php b/app/Http/Controllers/HealthController.php new file mode 100644 index 000000000..14603a484 --- /dev/null +++ b/app/Http/Controllers/HealthController.php @@ -0,0 +1,55 @@ +where('deleted_at', null) + ->where('type', '0') + ->count(); + } + + /** + * Handle the incoming request. + * + * @param Request $request + * @return JsonResponse|Response + * @throws BindingResolutionException + */ + public function __invoke(Request $request) + { + if ((int) RateLimiter::remaining('health', 30) < 1) { + return response()->make('Too many attempts.', 429); + } + + RateLimiter::hit('health'); + + return response()->json([ + 'status' => 'ok', + 'items' => self::getItems(), + 'users' => self::getUsers(), + ]); + } +} diff --git a/routes/web.php b/routes/web.php index e9c7ab31f..55a707690 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,7 @@ use App\Application; use App\Http\Controllers\Auth\LoginController; +use App\Http\Controllers\HealthController; use App\Http\Controllers\HomeController; use App\Http\Controllers\ImportController; use App\Http\Controllers\ItemController; @@ -111,3 +112,5 @@ Route::resource('api/item', ItemRestController::class); Route::get('import', ImportController::class)->name('items.import'); + +Route::get('/health', HealthController::class)->name('health');