src/App/Controller/DefaultController.php line 17

  1. <?php
  2. namespace App\Controller;
  3. use Aqarmap\Bundle\UserBundle\Services\Contracts\UserIpInfoServiceInterface;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpKernel\Exception\HttpException;
  10. use Symfony\Component\Routing\Attribute\Route;
  11. class DefaultController extends AbstractController
  12. {
  13. #[Route(path: '/health-check/{probeType}', options: ['i18n' => false])]
  14. public function healthCheck(Request $request, string $probeType, EntityManagerInterface $em, UserIpInfoServiceInterface $ipInfoService): JsonResponse
  15. {
  16. $dbConnected = false;
  17. if ('readiness' == $probeType) {
  18. // DB Connection Check
  19. try {
  20. $em->getConnection()->connect();
  21. $dbConnected = $em->getConnection()->isConnected();
  22. } catch (\Exception $exception) {
  23. throw new HttpException(500, sprintf('DB Connection Error! (%s)', $exception->getMessage()));
  24. }
  25. }
  26. $date = new \DateTime();
  27. return $this->json([
  28. 'status' => 'ok',
  29. 'date' => $date->format('r'),
  30. 'db_connection' => $dbConnected,
  31. 'client_ip' => $request->getClientIp(),
  32. ]);
  33. }
  34. #[Route(path: '/debug', options: ['i18n' => true])]
  35. public function debug(): Response
  36. {
  37. return $this->render('Default/debug.html.twig');
  38. }
  39. }