You've already forked Php-Template
feat: implement JWT authentication and scope validation middleware #11
@@ -77,7 +77,7 @@ services:
|
|||||||
WORKERS: 1
|
WORKERS: 1
|
||||||
DEBUG: 1
|
DEBUG: 1
|
||||||
REDIS_HOST: redis
|
REDIS_HOST: redis
|
||||||
POSTGRES_HOST: postgres
|
DB_HOST: postgres
|
||||||
JWT_SIGNING_KEY: a-string-secret-at-least-256-bits-long
|
JWT_SIGNING_KEY: a-string-secret-at-least-256-bits-long
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
|
|||||||
@@ -4,18 +4,41 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Siteworxpro\App\Controllers;
|
namespace Siteworxpro\App\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Database\PostgresConnection;
|
||||||
use Nyholm\Psr7\ServerRequest;
|
use Nyholm\Psr7\ServerRequest;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Siteworxpro\App\Http\JsonResponseFactory;
|
use Siteworxpro\App\Http\JsonResponseFactory;
|
||||||
|
use Siteworxpro\App\Models\Model;
|
||||||
|
use Siteworxpro\App\Services\Facades\Redis;
|
||||||
|
use Siteworxpro\HttpStatus\CodesEnum;
|
||||||
|
|
||||||
class HealthcheckController extends Controller
|
class HealthcheckController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \JsonException
|
* @throws \JsonException
|
||||||
*/
|
*/
|
||||||
public function get(ServerRequest $request): ResponseInterface
|
public function get(ServerRequest $request): ResponseInterface
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
|
/** @var PostgresConnection $conn */
|
||||||
|
$conn = Model::getConnectionResolver()->connection();
|
||||||
|
$conn->getPdo()->exec('SELECT 1');
|
||||||
|
|
||||||
|
$response = Redis::ping();
|
||||||
|
if ($response->getPayload() !== 'PONG') {
|
||||||
|
throw new \Exception('Redis ping failed');
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return JsonResponseFactory::createJsonResponse(
|
||||||
|
[
|
||||||
|
'status_code' => CodesEnum::SERVICE_UNAVAILABLE->value,
|
||||||
|
'message' => 'Healthcheck Failed',
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
],
|
||||||
|
CodesEnum::SERVICE_UNAVAILABLE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return JsonResponseFactory::createJsonResponse(
|
return JsonResponseFactory::createJsonResponse(
|
||||||
['status_code' => 200, 'message' => 'Healthcheck OK']
|
['status_code' => 200, 'message' => 'Healthcheck OK']
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ use Siteworxpro\App\Services\Facade;
|
|||||||
* @method static Status|null set(string $key, $value, $expireResolution = null, $expireTTL = null, $flag = null)
|
* @method static Status|null set(string $key, $value, $expireResolution = null, $expireTTL = null, $flag = null)
|
||||||
* @method static array keys(string $pattern)
|
* @method static array keys(string $pattern)
|
||||||
* @method static int del(string $key)
|
* @method static int del(string $key)
|
||||||
|
* @method static Status ping()
|
||||||
*/
|
*/
|
||||||
class Redis extends Facade
|
class Redis extends Facade
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user