Added an open healthcheck API endpoint.

This commit is contained in:
Abdulmhsen B. A. A
2024-04-27 11:50:41 +03:00
parent b227778eb1
commit d7d49d9a5d
2 changed files with 26 additions and 2 deletions

View File

@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace App\API\System;
use App\Libs\Attributes\Route\Get;
use App\Libs\HTTP_STATUS;
use Psr\Http\Message\ResponseInterface as iResponse;
use Psr\Http\Message\ServerRequestInterface as iRequest;
final class HealthCheck
{
public const string URL = '%{api.prefix}/system/healthcheck';
#[Get(self::URL . '[/]', name: 'system.healthcheck')]
public function __invoke(iRequest $request): iResponse
{
return api_response(HTTP_STATUS::HTTP_OK, [
'status' => 'ok',
'message' => 'System is healthy',
]);
}
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Libs\Middlewares; namespace App\Libs\Middlewares;
use App\API\System\HealthCheck;
use App\Libs\Config; use App\Libs\Config;
use App\Libs\HTTP_STATUS; use App\Libs\HTTP_STATUS;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
@@ -17,8 +18,7 @@ final class APIKeyRequiredMiddleware implements MiddlewareInterface
public const string KEY_NAME = 'apikey'; public const string KEY_NAME = 'apikey';
private const array OPEN_ROUTES = [ private const array OPEN_ROUTES = [
\App\API\Webhooks\Index::URL, HealthCheck::URL,
\App\API\System\HealthCheck::URL,
]; ];
/** /**