This commit is contained in:
2025-11-30 02:51:15 +01:00
parent 3ebfb8c7f6
commit 2fb5093c7f
9 changed files with 217 additions and 205 deletions

View File

@@ -1,49 +1,58 @@
<?php
// api/index.php
// /api/index.php
// Optional: zentrale Config laden (wenn du magst)
// require __DIR__ . '/../config/fileload.php';
declare(strict_types=1);
require __DIR__ . '/../config/fileload.php';
// Basis-Header (CORS, JSON)
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(204);
exit;
}
// Pfad aus der URL holen, z.B. /quickcheck?...
$uri = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
// Pfad aus der URL holen
$uri = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
$path = rtrim($uri, '/');
if ($path === '') {
$path = '/';
}
// Routing
switch ($path) {
case '/quickcheck':
require __DIR__ . '/target/quickcheck.php';
$result = quickcheck_handle_request();
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
break;
case '/browser.quick.test':
require __DIR__ . '/target/browser.quick.test.php';
$result = browser_quick_test_handle_request();
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
break;
default:
http_response_code(404);
echo json_encode([
'success' => false,
'error' => 'Unknown endpoint',
'path' => $path,
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
break;
// Root-Info (optional)
if ($path === '/') {
echo json_encode([
'ok' => true,
'service' => 'usbcheck-api',
'version' => 1,
'endpoints' => [
'/v1/quickcheck',
'/v1/browser.quick.test',
'/internal/* (geschützt)',
],
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
exit;
}
// Routing nach Bereich
if (str_starts_with($path, '/v1/')) {
require __DIR__ . '/router.v1.php';
exit;
}
if (str_starts_with($path, '/internal/')) {
require __DIR__ . '/router.internal.php';
exit;
}
// Fallback: unbekannter Bereich
http_response_code(404);
echo json_encode([
'ok' => false,
'error' => 'Unknown API area',
'path' => $path,
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);