Updated response handling and added 404 page
The code changes include an update to the response handling in index.php. Now, it checks if the request URI is '/metrics'. If so, it continues with the previous behavior of executing a script and outputting its result. If not, it loads a new 404 error page using Twig templating engine. A new file '404.twig' has been added under templates directory which serves as a custom 404 error page. It displays the requested URI and provides a link back to '/metrics'.
This commit is contained in:
parent
f7f3cb9704
commit
f06c804c24
21
index.php
21
index.php
@ -1,6 +1,17 @@
|
||||
<?php
|
||||
header('Content-Type: text/plain; version=0.0.4');
|
||||
$config = getenv('CONFIG_FILE');
|
||||
$phpbin = getenv('PHP_BINARY');
|
||||
$output = shell_exec('CONFIG_FILE="' . $config . '" ' . $phpbin . ' ' . $_SERVER['DOCUMENT_ROOT'] . 'script.php');
|
||||
echo $output;
|
||||
|
||||
if($_SERVER["REQUEST_URI"] == '/metrics') {
|
||||
header('Content-Type: text/plain; version=0.0.4');
|
||||
$config = getenv('CONFIG_FILE');
|
||||
$phpbin = getenv('PHP_BINARY');
|
||||
$output = shell_exec('CONFIG_FILE="' . $config . '" ' . $phpbin . ' ' . $_SERVER['DOCUMENT_ROOT'] . 'script.php');
|
||||
echo $output;
|
||||
} else {
|
||||
require_once('vendor/autoload.php');
|
||||
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"]]);
|
||||
}
|
12
templates/404.twig
Normal file
12
templates/404.twig
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<meta charset="UTF-8">
|
||||
<title>Page Title</title>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<style>
|
||||
</style>
|
||||
<body>
|
||||
<h1>404 Uri {{ path }} not found</h1>
|
||||
<p><a href="/metrics">/metrics</a></p>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user