PABX da Simples IP
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.
 
 
 
 
 
 

67 lines
1.9 KiB

<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once '/var/www/html/include/util/util.php';
//error_reporting(E_ALL);
ini_set('display_errors', 0);
use app\controllers\QueueController;
use app\controllers\CallController;
use app\controllers\AuthController;
use app\middleware\AuthMiddleware;
use app\controllers\MeetController;
use app\shared\Logger;
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") {
echo "teste OK";
// header("HTTP/1.1 200 OK");
die();
}
$logger = new Logger('api' . date('Ymd'), true);
$app = AppFactory::create();
$app->addRoutingMiddleware();
$app->add(new CorsMiddleware());
$app->addErrorMiddleware(false, true, true);
$logger->debug("calling API", true);
// Define app routes
$app->get('/api/v2/teste', function () {
echo "teste OK";
die();
});
$app->group('/api/v2', AuthController::route());
$app->group('/api/v2/meet', MeetController::route());
$logger->debug("After auth", true);
$app->group('/api/v2', function (RouteCollectorProxy $group) {
$group->group('/call', CallController::route());
$group->group('/queue', QueueController::route());
})->add(new AuthMiddleware);
$logger->debug("will run the API.", true);
// Middleware de Fallback
try {
$app->run();
} catch (Exception $e) {
$logger->error("Exeption running app: " . $e->getMessage(), true);
die(json_encode(array("status" => "failed", "message" => "This action is not allowed")));
}