sadasd
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
// /api/index.php
|
// /api/index.php
|
||||||
// Optional: zentrale Config laden (wenn du magst)
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
$apibasedir = $_SERVER['DOCUMENT_ROOT'];
|
|
||||||
require $apibasedir. '/../config/fileload.php';
|
$apibasedir = $_SERVER['DOCUMENT_ROOT']; // bei dir: /.../projects/usbcheck/staging/api
|
||||||
|
require $apibasedir . '/../config/fileload.php';
|
||||||
|
|
||||||
// Basis-Header (CORS, JSON)
|
// Basis-Header (CORS, JSON)
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
@@ -41,12 +41,18 @@ if ($path === '/') {
|
|||||||
|
|
||||||
// Routing nach Bereich
|
// Routing nach Bereich
|
||||||
if (str_starts_with($path, '/v1/')) {
|
if (str_starts_with($path, '/v1/')) {
|
||||||
require_once $apibasedir.'/router/router.v1.php';
|
// alles hinter /v1/ in Segmente zerlegen
|
||||||
|
$rel = substr($path, strlen('/v1/')); // z.B. "browser.quick.test" oder "quickcheck" oder "foo/bar"
|
||||||
|
$rel = ltrim($rel, '/');
|
||||||
|
$segments = $rel === '' ? [] : explode('/', $rel);
|
||||||
|
|
||||||
|
require_once $apibasedir . '/router/router.v1.php';
|
||||||
|
router_v1_dispatch($segments);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str_starts_with($path, '/internal/')) {
|
if (str_starts_with($path, '/internal/')) {
|
||||||
require_once $apibasedir. '/router/router.internal.php';
|
require_once $apibasedir . '/router/router.internal.php';
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,19 @@ declare(strict_types=1);
|
|||||||
/**
|
/**
|
||||||
* Router für /v1/...
|
* Router für /v1/...
|
||||||
*
|
*
|
||||||
* Wird von /api/index.php aufgerufen:
|
* Wird von /api/index.php so aufgerufen:
|
||||||
* router_v1_dispatch($segments, $apibasedir)
|
* router_v1_dispatch($segments)
|
||||||
*
|
*
|
||||||
* $segments[0] ist dann z.B. "browser.quick.test" oder "quickcheck"
|
* $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, string $apibasedir): void
|
// Basisverzeichnis der API ermitteln (…/api)
|
||||||
|
$apibasedir = dirname(__DIR__);
|
||||||
|
|
||||||
|
function router_v1_dispatch(array $segments): void
|
||||||
{
|
{
|
||||||
|
global $apibasedir;
|
||||||
|
|
||||||
if (empty($segments[0])) {
|
if (empty($segments[0])) {
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
@@ -73,7 +76,6 @@ function router_v1_dispatch(array $segments, string $apibasedir): void
|
|||||||
try {
|
try {
|
||||||
$result = $handler();
|
$result = $handler();
|
||||||
|
|
||||||
// Falls der Handler mal kein Array zurückgibt
|
|
||||||
if (!is_array($result)) {
|
if (!is_array($result)) {
|
||||||
$result = [
|
$result = [
|
||||||
'ok' => false,
|
'ok' => false,
|
||||||
@@ -83,7 +85,6 @@ function router_v1_dispatch(array $segments, string $apibasedir): void
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTTP-Status aus Ergebnis ableiten (optional)
|
|
||||||
if (isset($result['ok']) && $result['ok'] === false) {
|
if (isset($result['ok']) && $result['ok'] === false) {
|
||||||
if (!http_response_code()) {
|
if (!http_response_code()) {
|
||||||
http_response_code(400);
|
http_response_code(400);
|
||||||
|
|||||||
Reference in New Issue
Block a user