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.
This commit is contained in:
parent
f3513ea80e
commit
265128d725
@ -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]);
|
||||
}
|
@ -7,8 +7,8 @@
|
||||
</style>
|
||||
<body>
|
||||
<h1>404 Uri {{ path }} not found</h1>
|
||||
<p><a href="/metrics">/metrics</a></p>
|
||||
<p><a href="/config">/config</a></p>
|
||||
<p><a href="/version">/version</a></p>
|
||||
{% for knownpath in knownpaths %}
|
||||
<p><a href="{{ knownpath }}">{{ knownpath }}</a></p>
|
||||
{% endfor %}
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user