Skip to content
Snippets Groups Projects
Commit 9ec312c6 authored by Fabrice Gangler's avatar Fabrice Gangler :art:
Browse files

chore: add minimal route

parent 33efb04a
No related branches found
No related tags found
No related merge requests found
Pipeline #75853 failed
<?php
/*
* This file is part of the Tajine software.
* <https://gitlab.adullact.net/adullact/pki/tajine>
*
* Copyright (c) ADULLACT <https://adullact.org>
* Association des Développeurs et Utilisateurs de Logiciels Libres
* pour les Administrations et les Collectivités Territoriales
*
* Tajine is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* You should have received a copy of the GNU Affero General Public License
* along with this software. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>.
*/
declare(strict_types=1);
namespace App\Controller;
use Doctrine\DBAL\Connection;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\String\Slugger\AsciiSlugger;
class HealthCheckController extends AbstractController
{
#[Route(
path:'/health-check',
name: 'app_health_check',
methods: ['GET', 'HEAD']
)]
public function healthCheck(Request $request, Connection $dbConnection): Response
{
// $softwareName = $this->getParameter('app.software.name');
$softwareName = "COMPTOIR_NAME_FIXME";
$httpCode = Response::HTTP_OK;
$dbStatusCode = "SUCCESSFUL";
try {
$dbConnection->fetchAllAssociative('SELECT * FROM doctrine_migration_versions');
} catch (\Exception $e) {
$httpCode = Response::HTTP_SERVICE_UNAVAILABLE;
$dbStatusCode = "FAILED";
}
$slugSoftwareName = strtolower((new AsciiSlugger())->slug("$softwareName")->toString()) ;
$headers = [
"x-$slugSoftwareName-database-status" => "DB_CONNECTION_$dbStatusCode",
];
if ($request->getMethod() === "HEAD") {
return new Response(status: $httpCode, headers: $headers);
} else {
return $this->render(
view: 'healthcheck.html.twig',
parameters: [
'dbStatusCode' => $dbStatusCode,
],
response: new Response(status: $httpCode, headers: $headers)
);
}
}
}
<?php
/*
* This file is part of the Tajine software.
* <https://gitlab.adullact.net/adullact/pki/tajine>
*
* Copyright (c) ADULLACT <https://adullact.org>
* Association des Développeurs et Utilisateurs de Logiciels Libres
* pour les Administrations et les Collectivités Territoriales
*
* Tajine is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* You should have received a copy of the GNU Affero General Public License
* along with this software. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>.
*/
declare(strict_types=1);
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
class HomeController extends AbstractController
{
#[Route(
'/',
name: 'app_home',
methods: ['GET', 'HEAD']
)]
public function index(): Response
{
return $this->render('home.html.twig');
}
}
<!DOCTYPE html>
<html class="no-js" lang="{{ app.request.locale|split('_')[0] }}">
<head>
<meta charset="UTF-8">
<title>{% block title %}Welcome!{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="{{ asset('css/vendor/bootstrap5.3.min.css') }}" rel="stylesheet">
{# <link href="{{ asset('css/webapp-tajine.css') }}" rel="stylesheet">#}
{# {% cspstyle %} <style></style> {% endcspstyle %}#}
<meta name="description" content="">
{#
<link rel="icon" href="/favicon.ico" sizes="any">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="icon.png">
#}
</head>
<body>
<div class="col-lg-8 mx-auto p-4 py-md-5">
<header class="d-flex align-items-center pb-3 mb-5 border-bottom">
HEADER
</header>
<main>
MAIN
{# read and display all flash messages #}
{% for label, messages in app.flashes %}
{% for message in messages %}
<div class="alert alert-{{ label }}">
{{ message }}
</div>
{% endfor %}
{% endfor %}
{# read and display several types of flash messages #}
{# {{% for label, messages in app.flashes(['success', 'warning', 'notice', 'error']) %}#}
{# <div class="alert alert-success">#}
{# {{ message }}#}
{# </div>#}
{# {% endfor %}#}
{% block body %}{% endblock %}
</main>
{% include "app_base_footer.html.twig" %}
</div>
</body>
</html>
<hr>
FOOTER
{% extends 'app_base.html.twig' %}
{% block title %}{{ 'public.health-check.head.title'|trans }} APP_NAME_FIXME{% endblock %}
{#{% block title %}{{ 'public.health-check.head.title'|trans }} {{ appShortName }}{% endblock %}#}
{% block body %}
{% set db_status_cssClass = 'table-danger' %}
{% set db_status_i18n = 'public.health-check.status.failed'|trans %}
{% if dbStatusCode == 'SUCCESSFUL' %}
{% set db_status_cssClass = 'table-info' %}
{% set db_status_i18n = 'public.health-check.status.successful'|trans %}
{% endif %}
<h1>{{ 'public.health-check.page.title'|trans }} APP_NAME_FIXME</h1>
{# <h1>{{ 'public.health-check.page.title'|trans }} {{ appShortName }}</h1>#}
<hr class="col-3 col-md-2 mb-5">
<div class="col-md-6">
<table class="table table-hover">
<thead>
<tr>
<th scope="col">{{ 'public.health-check.col.resources'|trans }}</th>
<th scope="col">{{ 'public.health-check.col.status'|trans }}</th>
<th scope="col">{{ 'public.health-check.col.status.code'|trans }}</th>
</tr>
</thead>
<tbody class="table-group-divider">
<tr>
<td>{{ 'public.health-check.line.database'|trans }}</td>
<td class="{{ db_status_cssClass }}">{{ db_status_i18n }}</td>
<td id="webapp-database-status">DB_CONNECTION_{{ dbStatusCode }}</td>
</tr>
</tbody>
</table>
</div>
{% endblock %}
{% extends 'app_base.html.twig' %}
{% block title %}Hello HomeController!{% endblock %}
{% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>
<div class="example-wrapper">
<h1>HOME PAGE ✅</h1>
</div>
{% endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment