Files
api/services/nginx/app/routes/optionsRoute.php
T

32 lines
1.2 KiB
PHP

<?php
namespace routes;
use traits\route_t;
class optionsRoute
{
use route_t;
public function run(): void
{
// When the OPTIONS method is requested, accept all using regex
$this->options('/.*', function () {
global $CORS;
$origin = $_SERVER['HTTP_ORIGIN'] ?? '';
$allowed_origins = array_map('trim', explode(',', (string)($CORS ?? '*')));
if ($CORS === '*' || ($origin && in_array($origin, $allowed_origins))) {
header("Access-Control-Allow-Origin: " . ($origin ?: '*'));
header("Access-Control-Allow-Credentials: true");
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Customer-Number, X-Release-Trace, X-Release-Channel, X-Frontend-Version, Cache-Control, Pragma, *');
header('Content-Type: application/json');
http_response_code(200);
} else {
http_response_code(403);
echo json_encode(['success' => false, 'message' => 'CORS origin not allowed']);
}
});
}
}