2022-01-26 18:48:42 +01:00
|
|
|
<?php declare(strict_types=1);
|
2022-01-31 20:01:06 +01:00
|
|
|
|
2024-04-19 16:19:17 +02:00
|
|
|
use App\Service\BindAPI;
|
2022-01-31 20:01:06 +01:00
|
|
|
|
2022-01-26 18:48:42 +01:00
|
|
|
error_reporting(error_level: E_ALL);
|
|
|
|
|
2022-01-24 18:59:00 +01:00
|
|
|
require dirname(path: __DIR__) . '/vendor/autoload.php';
|
2022-01-18 19:14:24 +01:00
|
|
|
|
2024-04-25 20:58:01 +02:00
|
|
|
$parsedUrl = parse_url(url: $_SERVER['REQUEST_URI'], component: PHP_URL_PATH);
|
|
|
|
$uri = explode(separator: '/', string: $parsedUrl);
|
2022-02-06 18:00:15 +01:00
|
|
|
|
2024-04-25 20:58:01 +02:00
|
|
|
$baseRoutes = ['app', 'api'];
|
|
|
|
$uriPrefix = $uriFirstThreeLetters = substr(string: $uri[1], offset: 0, length: 3);
|
|
|
|
|
|
|
|
|
|
|
|
if (!in_array(needle: $uriPrefix, haystack: $baseRoutes)) {
|
|
|
|
// only handle $baseRoutes, elso go to swagger ui
|
2022-02-06 18:00:15 +01:00
|
|
|
$scheme = $_SERVER['REQUEST_SCHEME'];
|
|
|
|
$host = $_SERVER['SERVER_NAME'];
|
|
|
|
$header = "$scheme://$host/openapi/index.html";
|
|
|
|
header(header: "Location: $header");
|
|
|
|
exit(0);
|
2022-01-18 19:14:24 +01:00
|
|
|
}
|
2022-09-17 15:54:20 +02:00
|
|
|
|
2022-02-06 18:00:15 +01:00
|
|
|
header(header: "Access-Control-Allow-Origin: *");
|
|
|
|
header(header: "Content-Type: application/json; charset=UTF-8");
|
|
|
|
header(header: "Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE");
|
|
|
|
header(header: "Access-Control-Max-Age: 3600");
|
|
|
|
header(header: "Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
|
|
|
|
2022-01-18 19:14:24 +01:00
|
|
|
$requestMethod = $_SERVER["REQUEST_METHOD"];
|
|
|
|
|
2024-04-25 20:58:01 +02:00
|
|
|
if ($requestMethod === "OPTIONS") {
|
|
|
|
// Respond with OK status code for preflight requests
|
|
|
|
http_response_code(response_code: 200);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2022-01-31 20:01:06 +01:00
|
|
|
try {
|
2024-04-17 15:27:21 +02:00
|
|
|
$app = new BindAPI(quiet: false);
|
2022-09-17 15:54:20 +02:00
|
|
|
$app->handleRequest(requestMethod: $requestMethod, uri: $uri);
|
2022-01-31 20:01:06 +01:00
|
|
|
} catch (Exception $e) {
|
|
|
|
echo json_encode(value: [
|
|
|
|
'error' => $e->getMessage()
|
|
|
|
]);
|
|
|
|
}
|