index.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. use FrameworkX\App;
  17. use Middlewares\ExternalAuthMiddleware;
  18. use Libs\ModelFactory;
  19. try {
  20. $adb = ModelFactory::adb();
  21. $GLOBALS['ADB'] = $adb;
  22. } catch (\Throwable $e) {
  23. http_response_code(500);
  24. header('Content-Type: application/json; charset=utf-8');
  25. echo json_encode(['error' => 'DB init failed', 'detail' => $e->getMessage()], JSON_UNESCAPED_SLASHES);
  26. exit(1);
  27. }
  28. $app = new App();
  29. $authExternal = new ExternalAuthMiddleware();
  30. $app->get('/hello', $authExternal, \Controllers\HelloController::class);
  31. $app->post('/send/mail', $authExternal, \Controllers\MailSendController::class);
  32. $app->run();