From 265128d725468deabc7225de43cab9fb6b6d0c8d Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Fri, 14 Jun 2024 20:49:33 +0200 Subject: [PATCH] Update known paths in 404 error template based on available routes - Adjusted handling of known paths to dynamically include additional routes if a specific directory exists, enhancing user experience. --- index.php | 9 +++++++-- templates/404.twig | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index 8acb04b..2fd2c58 100644 --- a/index.php +++ b/index.php @@ -10,7 +10,7 @@ if($_SERVER["REQUEST_URI"] == '/metrics') { header('Content-Type: application/json'); require_once getenv('CONFIG_FILE'); echo json_encode($config); -} elseif ($_SERVER["REQUEST_URI"] == '/version') { +} elseif ($_SERVER["REQUEST_URI"] == '/version' && is_dir($_SERVER['DOCUMENT_ROOT'] . '/.git')) { header('Content-Type: application/json'); $git = [ 'lastCommit' => trim(shell_exec('git rev-parse HEAD')), @@ -20,10 +20,15 @@ if($_SERVER["REQUEST_URI"] == '/metrics') { echo json_encode($git); } else { require_once('vendor/autoload.php'); + $knownpaths = [ + '/metrics', + '/config' + ]; + if (is_dir($_SERVER['DOCUMENT_ROOT'] . '/.git')) $knownpaths[] = '/version'; http_response_code(404); $loader = new \Twig\Loader\FilesystemLoader('templates'); $twig = new \Twig\Environment($loader, [ 'cache' => 'twig_cache', ]); - echo $twig->render('404.twig', ['path' => $_SERVER["REQUEST_URI"]]); + echo $twig->render('404.twig', ['path' => $_SERVER["REQUEST_URI"], 'knownpaths' => $knownpaths]); } \ No newline at end of file diff --git a/templates/404.twig b/templates/404.twig index f68e587..fe2a0a0 100644 --- a/templates/404.twig +++ b/templates/404.twig @@ -7,8 +7,8 @@

404 Uri {{ path }} not found

-

/metrics

-

/config

-

/version

+{% for knownpath in knownpaths %} +

{{ knownpath }}

+{% endfor %} \ No newline at end of file