| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- require __DIR__ . '/../vendor/autoload.php';
- $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
- $file = __DIR__ . $path;
- if (php_sapi_name() === 'cli-server' && is_file($file)) {
- return false;
- }
- if (class_exists(Dotenv\Dotenv::class) && file_exists(__DIR__ . '/../.env')) {
- Dotenv\Dotenv::createImmutable(
- dirname(__DIR__),
- null,
- true
- )->safeLoad();
- }
- error_reporting(E_ALL);
- ini_set('display_errors', 1); // Para depuração
- ini_set('display_startup_errors', 1);
- use FrameworkX\App;
- use Middlewares\HmacAuthMiddleware;
- use Middlewares\JWTAuthMiddleware;
- use Middlewares\CorsControl;
- use Psr\Http\Message\ServerRequestInterface;
- use React\Http\Message\Response;
- $app = new App();
- // Instancia os middlewares
- $authHmac = new HmacAuthMiddleware();
- $authJwt = new JWTAuthMiddleware();
- $cors = new CorsControl();
- // Função para envolver rotas com CORS
- $withCors = function ($handler) use ($cors) {
- return function (ServerRequestInterface $request) use ($handler, $cors) {
- return $cors($request, $handler);
- };
- };
- // Rotas com CORS aplicado
- $app->get('/hmachelloworld', $withCors($authHmac), \Controllers\HelloController::class);
- $app->get('/jwthelloworld', $withCors($authJwt), \Controllers\HelloController::class);
- //Rotas User
- $app->post('/login', $withCors(\Controllers\LoginController::class));
- $app->post('/register', $withCors(\Controllers\RegisterController::class));
- //Rotas Category
- $app->get('/category', $withCors(\Controllers\CategoryController::class));
- $app->post('/category', $withCors(\Controllers\CategoryController::class));
- $app->post('/category/delete', $withCors(\Controllers\CategoryController::class));
- $app->post('/category/add-product', $withCors(\Controllers\CategoryController::class));
- //Rotas Product
- $app->get('/product', $withCors(\Controllers\ProductController::class));
- $app->post('/product', $withCors(\Controllers\ProductController::class));
- $app->run();
|