<?php
use App\Kernel;
use Symfony\Component\HttpFoundation\Request;
require dirname(__DIR__).'/config/bootstrap.php';
function sendJpgHeaders(string $path)
{
header('Content-type: '.mime_content_type($path));
$modifiedDate = gmdate('D, d M Y H:i:s', filemtime($path));
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
if (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= filemtime($path)) {
// send the last mod time of the file back
$code = 304;
// header('Last-Modified: ' . $modifiedDate . ' GMT', true, $code);
}
} else {
// header('Last-Modified: ' . $modifiedDate);
// header('Cache-Control: must-revalidate');
}
}
if (isset($_SERVER['REQUEST_URI']) && 0 === strpos($_SERVER['REQUEST_URI'], '/categoryimages/media')) {
header('Access-Control-Allow-Origin: *');
$path = $_ENV['APP_PATH_NFS_CATEGORIES'].substr($_SERVER['REQUEST_URI'], 21);
if ($pos = strpos($path, '?')) {
$path = substr($path, 0, $pos);
}
if (is_file($path)) {
sendJpgHeaders($path);
return readfile($path);
}
echo $path.' does not exist';
exit;
}
if ($_SERVER['APP_DEBUG']) {
umask(0000);
Symfony\Component\ErrorHandler\Debug::enable();
}
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);