This commit is contained in:
2025-11-30 03:39:16 +01:00
parent 98a9f55c64
commit 3607d71a40
2 changed files with 16 additions and 15 deletions

View File

@@ -3,7 +3,7 @@
// Optional: zentrale Config laden (wenn du magst)
declare(strict_types=1);
$apibasedir = $_SERVER['DOCUMENT_ROOT'];
echo $apibasedir = $_SERVER['DOCUMENT_ROOT'];
require $apibasedir. '/../config/fileload.php';
// Basis-Header (CORS, JSON)

View File

@@ -1,5 +1,5 @@
<?php
// /api/router.v1.php
// /api/router/router.v1.php
declare(strict_types=1);
@@ -7,12 +7,14 @@ declare(strict_types=1);
* Router für /v1/...
*
* Wird von /api/index.php aufgerufen:
* router_v1_dispatch($segments)
* router_v1_dispatch($segments, $apibasedir)
*
* $segments[0] ist dann z.B. "browser.quick.test" oder "quickcheck"
*
* $apibasedir ist der Pfad auf /api (also das Root des API-Vhosts).
*/
function router_v1_dispatch(array $segments): void
function router_v1_dispatch(array $segments, string $apibasedir): void
{
if (empty($segments[0])) {
http_response_code(404);
@@ -27,12 +29,12 @@ function router_v1_dispatch(array $segments): void
switch ($endpoint) {
case 'quickcheck':
$file = $apibasedir. '/v1/target/quickcheck.php';
$file = $apibasedir . '/v1/target/quickcheck.php';
$handler = 'quickcheck_handle_request';
break;
case 'browser.quick.test':
$file = $apibasedir. '/v1/result/browser.quick.test.php';
$file = $apibasedir . '/v1/result/browser.quick.test.php';
$handler = 'browser_quick_test_handle_request';
break;
@@ -41,7 +43,7 @@ function router_v1_dispatch(array $segments): void
echo json_encode([
'ok' => false,
'error' => 'Unknown v1 endpoint',
'endpoint'=> $endpoint,
'endpoint' => $endpoint,
], JSON_UNESCAPED_UNICODE);
return;
}
@@ -51,7 +53,7 @@ function router_v1_dispatch(array $segments): void
echo json_encode([
'ok' => false,
'error' => 'Endpoint file not found',
'file' => basename($file),
'file' => $file,
], JSON_UNESCAPED_UNICODE);
return;
}
@@ -77,13 +79,12 @@ function router_v1_dispatch(array $segments): void
'ok' => false,
'error' => 'Handler did not return array',
'raw' => $result,
'handler'=> $handler,
'handler' => $handler,
];
}
// HTTP-Status aus Ergebnis ableiten (optional)
if (isset($result['ok']) && $result['ok'] === false) {
// Bei Fehler eher 400 als 200, außer du willst es anders
if (!http_response_code()) {
http_response_code(400);
}