forked from SimplesIP/pabx-app
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.4 KiB
48 lines
1.4 KiB
8 months ago
|
<?php
|
||
|
|
||
|
require __DIR__ . '/../vendor/autoload.php';
|
||
|
|
||
|
// error_reporting(E_ALL);
|
||
|
// ini_set('display_errors', 1);
|
||
|
|
||
|
use app\controllers\QueueController;
|
||
|
use app\controllers\CallController;
|
||
|
use app\controllers\AuthController;
|
||
|
use app\middleware\AuthMiddleware;
|
||
|
|
||
|
use Slim\Factory\AppFactory;
|
||
|
use Slim\Routing\RouteCollectorProxy;
|
||
|
use Tuupola\Middleware\CorsMiddleware;
|
||
|
|
||
|
header('Access-Control-Allow-Origin: *');
|
||
|
header('Access-Control-Allow-Credentials: true');
|
||
|
header("Access-Control-Allow-Methods: HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS");
|
||
|
header("Access-Control-Allow-Headers: X-API-KEY, Origin, ngrok-skip-browser-warning, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Access-Control-Request-Headers, Authorization");
|
||
|
header('Content-Type: application/json');
|
||
|
$method = $_SERVER['REQUEST_METHOD'];
|
||
|
if ($method == "OPTIONS") {
|
||
|
header("HTTP/1.1 200 OK");
|
||
|
die();
|
||
|
}
|
||
|
|
||
|
$app = AppFactory::create();
|
||
|
$app->addRoutingMiddleware();
|
||
|
$app->add(new CorsMiddleware());
|
||
|
$app->addErrorMiddleware(false, true, true);
|
||
|
|
||
|
// Define app routes
|
||
|
$app->group('/api/v2', AuthController::route());
|
||
|
|
||
|
$app->group('/api/v2', function (RouteCollectorProxy $group) {
|
||
|
$group->group('/call', CallController::route());
|
||
|
$group->group('/queue', QueueController::route());
|
||
|
})->add(new AuthMiddleware);
|
||
|
|
||
|
// Middleware de Fallback
|
||
|
|
||
|
try {
|
||
|
$app->run();
|
||
|
} catch (Exception $e) {
|
||
|
die(json_encode(array("status" => "failed", "message" => "This action is not allowed")));
|
||
|
}
|