47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
use App\Service\BindAPI;
|
|
|
|
error_reporting(error_level: E_ALL);
|
|
|
|
require dirname(path: __DIR__) . '/vendor/autoload.php';
|
|
|
|
$parsedUrl = parse_url(url: $_SERVER['REQUEST_URI'], component: PHP_URL_PATH);
|
|
$uri = explode(separator: '/', string: $parsedUrl);
|
|
|
|
$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
|
|
$scheme = $_SERVER['REQUEST_SCHEME'];
|
|
$host = $_SERVER['SERVER_NAME'];
|
|
$header = "$scheme://$host/openapi/index.html";
|
|
header(header: "Location: $header");
|
|
exit(0);
|
|
}
|
|
|
|
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");
|
|
|
|
$requestMethod = $_SERVER["REQUEST_METHOD"];
|
|
|
|
if ($requestMethod === "OPTIONS") {
|
|
// Respond with OK status code for preflight requests
|
|
http_response_code(response_code: 200);
|
|
exit();
|
|
}
|
|
|
|
try {
|
|
$app = new BindAPI(quiet: false);
|
|
$app->handleRequest(requestMethod: $requestMethod, uri: $uri);
|
|
} catch (Exception $e) {
|
|
echo json_encode(value: [
|
|
'error' => $e->getMessage()
|
|
]);
|
|
}
|