Anpassung für Aufruf für proxy
This commit is contained in:
+56
-4
@@ -14,6 +14,7 @@ session_start();
|
||||
function runApplication(): void
|
||||
{
|
||||
$config = require dirname(__DIR__) . '/config.php';
|
||||
setAppConfig($config);
|
||||
|
||||
[$bookingRepository, $invoiceRepository] = resolveRepositories($config);
|
||||
|
||||
@@ -21,7 +22,11 @@ function runApplication(): void
|
||||
$invoicePdfService = new InvoicePdfService($config);
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
|
||||
$path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
|
||||
$path = requestPath();
|
||||
|
||||
if (serveStaticAssetIfRequested($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($method === 'POST' && $path === '/book') {
|
||||
handlePublicBooking($bookingService);
|
||||
@@ -52,6 +57,53 @@ function runApplication(): void
|
||||
renderHome($bookingService, $config);
|
||||
}
|
||||
|
||||
function requestPath(): string
|
||||
{
|
||||
$path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
|
||||
$basePath = basePath();
|
||||
|
||||
if ($basePath !== '' && str_starts_with($path, $basePath)) {
|
||||
$path = substr($path, strlen($basePath)) ?: '/';
|
||||
}
|
||||
|
||||
if ($path === '') {
|
||||
return '/';
|
||||
}
|
||||
|
||||
return '/' . ltrim($path, '/');
|
||||
}
|
||||
|
||||
function serveStaticAssetIfRequested(string $path): bool
|
||||
{
|
||||
if (!str_starts_with($path, '/assets/')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$file = dirname(__DIR__) . $path;
|
||||
if (!is_file($file)) {
|
||||
http_response_code(404);
|
||||
echo 'Datei nicht gefunden.';
|
||||
return true;
|
||||
}
|
||||
|
||||
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
|
||||
$mimeTypes = [
|
||||
'css' => 'text/css; charset=UTF-8',
|
||||
'js' => 'application/javascript; charset=UTF-8',
|
||||
'svg' => 'image/svg+xml',
|
||||
'png' => 'image/png',
|
||||
'jpg' => 'image/jpeg',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'webp' => 'image/webp',
|
||||
];
|
||||
|
||||
header('Content-Type: ' . ($mimeTypes[$extension] ?? 'application/octet-stream'));
|
||||
header('Content-Length: ' . (string) filesize($file));
|
||||
readfile($file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function resolveRepositories(array $config): array
|
||||
{
|
||||
$databaseFile = $config['database']['credentials_file'];
|
||||
@@ -155,17 +207,17 @@ function handleAdminRequest(string $path, string $method, BookingService $bookin
|
||||
flash('error', $exception->getMessage());
|
||||
}
|
||||
|
||||
redirect('/admin/order?id=' . urlencode((string) ($_POST['booking_id'] ?? '')));
|
||||
redirect('admin/order?id=' . urlencode((string) ($_POST['booking_id'] ?? '')));
|
||||
}
|
||||
|
||||
if ($method === 'POST' && $path === '/admin/order/invoice') {
|
||||
try {
|
||||
$invoiceId = $bookingService->createInvoiceForBooking((string) ($_POST['booking_id'] ?? ''), $_POST);
|
||||
flash('success', 'Die Rechnung wurde erstellt.');
|
||||
redirect('/admin/order?id=' . urlencode((string) ($_POST['booking_id'] ?? '')) . '&invoice=' . urlencode($invoiceId));
|
||||
redirect('admin/order?id=' . urlencode((string) ($_POST['booking_id'] ?? '')) . '&invoice=' . urlencode($invoiceId));
|
||||
} catch (Throwable $exception) {
|
||||
flash('error', $exception->getMessage());
|
||||
redirect('/admin/order?id=' . urlencode((string) ($_POST['booking_id'] ?? '')));
|
||||
redirect('admin/order?id=' . urlencode((string) ($_POST['booking_id'] ?? '')));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user