2025-12-17 10:43:03 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Bootstrap;
|
|
|
|
|
|
2025-12-17 13:56:32 +07:00
|
|
|
use App\Middleware\CorsMiddleware;
|
2025-12-17 10:43:03 +07:00
|
|
|
use Slim\App;
|
|
|
|
|
use Slim\Factory\AppFactory;
|
|
|
|
|
use Slim\Middleware\BodyParsingMiddleware;
|
|
|
|
|
|
|
|
|
|
class AppBootstrap
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Create and configure Slim App instance
|
|
|
|
|
*
|
|
|
|
|
* @return App
|
|
|
|
|
*/
|
|
|
|
|
public static function create(): App
|
|
|
|
|
{
|
|
|
|
|
$app = AppFactory::create();
|
|
|
|
|
|
2025-12-17 13:56:32 +07:00
|
|
|
// Add CORS middleware FIRST (before routing)
|
|
|
|
|
$app->add(new CorsMiddleware());
|
|
|
|
|
|
2025-12-17 10:43:03 +07:00
|
|
|
// Add body parsing middleware
|
|
|
|
|
$app->addBodyParsingMiddleware();
|
|
|
|
|
|
|
|
|
|
// Add routing middleware
|
|
|
|
|
$app->addRoutingMiddleware();
|
|
|
|
|
|
|
|
|
|
// Add error middleware
|
|
|
|
|
$app->addErrorMiddleware(true, true, true);
|
|
|
|
|
|
|
|
|
|
return $app;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|