index.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. require __DIR__ . '/../vendor/autoload.php';
  3. $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
  4. $file = __DIR__ . $path;
  5. if (php_sapi_name() === 'cli-server' && is_file($file)) {
  6. return false;
  7. }
  8. if (class_exists(Dotenv\Dotenv::class) && file_exists(__DIR__ . '/../.env')) {
  9. Dotenv\Dotenv::createImmutable(
  10. dirname(__DIR__),
  11. null,
  12. true
  13. )->safeLoad();
  14. }
  15. error_reporting(E_ALL);
  16. ini_set('display_errors', 1); // Para depuração
  17. ini_set('display_startup_errors', 1);
  18. use FrameworkX\App;
  19. use Middlewares\HmacAuthMiddleware;
  20. use Middlewares\JWTAuthMiddleware;
  21. use Middlewares\CorsControl;
  22. use Psr\Http\Message\ServerRequestInterface;
  23. use React\Http\Message\Response;
  24. $app = new App();
  25. // Instancia os middlewares
  26. $authHmac = new HmacAuthMiddleware();
  27. $authJwt = new JWTAuthMiddleware();
  28. $cors = new CorsControl();
  29. // Função para envolver rotas com CORS
  30. $withCors = function ($handler) use ($cors) {
  31. return function (ServerRequestInterface $request) use ($handler, $cors) {
  32. return $cors($request, $handler);
  33. };
  34. };
  35. // Rotas com CORS aplicado
  36. $app->get('/hmachelloworld', $withCors($authHmac), \Controllers\HelloController::class);
  37. $app->get('/jwthelloworld', $withCors($authJwt), \Controllers\HelloController::class);
  38. //Rotas User
  39. $app->post('/login', $withCors(\Controllers\LoginController::class));
  40. $app->post('/register', $withCors(\Controllers\RegisterController::class));
  41. //Rotas Category
  42. $app->post('/category/get', $withCors(\Controllers\CategoryGetController::class) );
  43. $app->post('/category/create', $withCors(\Controllers\CategoryCreateController::class) );
  44. $app->post('/category/delete', $withCors(\Controllers\CategoryDeleteController::class) );
  45. $app->post('/category/add-product', $withCors(\Controllers\CategoryAddProductController::class) );
  46. //Rotas Product
  47. $app->post('/product/get', $withCors(\Controllers\ProductGetController::class));
  48. $app->post('/product/create', $withCors(\Controllers\ProductCreateController::class));
  49. $app->post('/product/update', $withCors(\Controllers\ProductUpdateController::class));
  50. $app->post('/product/delete', $withCors(\Controllers\ProductDeleteController::class));
  51. $app->run();