Files
kaffeekasse-saas/public/router_test.php
T
2026-06-17 16:45:14 +02:00

49 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
/**
* Router für die Test-/Entwicklungsumgebung mit Proxy-Support.
* Erkennt den code-server Proxy-Prefix (z.B. /proxy/8080 oder /absproxy/8080) und speichert ihn.
*
* Start: php -S 0.0.0.0:8080 public/router_test.php
*/
// Proxy-Prefix erkennen und speichern, dann aus REQUEST_URI entfernen
$requestUri = $_SERVER['REQUEST_URI'] ?? '/';
$pathOnly = parse_url($requestUri, PHP_URL_PATH) ?: '/';
$proxyPrefix = '';
if (preg_match('#^(/(?:abs)?proxy/\d+)(/.*)?$#', $pathOnly, $matches)) {
$proxyPrefix = $matches[1];
$subPath = isset($matches[2]) && $matches[2] !== '' ? $matches[2] : '/';
// REQUEST_URI umschreiben für die Anwendung
$_SERVER['REQUEST_URI'] = $subPath;
}
// Proxy-Prefix global verfügbar machen für base_path()
$_SERVER['KAFFEEKASSE_PROXY_PREFIX'] = $proxyPrefix;
// Neu parsen nach Umschreibung
$path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
$file = __DIR__ . ($path === '/' ? '/index.php' : (string) $path);
// Statische Dateien direkt ausliefern (CSS, JS, etc.)
if ($path !== '/' && is_file($file)) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
$mimeTypes = [
'css' => 'text/css; charset=UTF-8',
'js' => 'application/javascript; charset=UTF-8',
'png' => 'image/png',
'jpg' => 'image/jpeg',
'svg' => 'image/svg+xml',
'ico' => 'image/x-icon',
];
if (isset($mimeTypes[$ext])) {
header('Content-Type: ' . $mimeTypes[$ext]);
}
return false;
}
require __DIR__ . '/index_test.php';