2025-12-17 10:43:03 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
require __DIR__ . '/../vendor/autoload.php';
|
|
|
|
|
|
|
|
|
|
use App\Bootstrap\AppBootstrap;
|
|
|
|
|
use App\Config\AppConfig;
|
|
|
|
|
use App\Modules\Auth\AuthRoutes;
|
|
|
|
|
use App\Modules\Health\HealthRoutes;
|
|
|
|
|
use App\Modules\Retribusi\Dashboard\DashboardRoutes;
|
|
|
|
|
use App\Modules\Retribusi\Realtime\RealtimeRoutes;
|
|
|
|
|
use App\Modules\Retribusi\RetribusiRoutes;
|
|
|
|
|
use App\Modules\Retribusi\Summary\SummaryRoutes;
|
|
|
|
|
|
|
|
|
|
// Load environment variables
|
|
|
|
|
AppConfig::loadEnv(__DIR__ . '/..');
|
|
|
|
|
|
|
|
|
|
// Bootstrap application
|
|
|
|
|
$app = AppBootstrap::create();
|
|
|
|
|
|
2025-12-17 11:08:04 +07:00
|
|
|
// Root route - redirect to docs
|
|
|
|
|
$app->get('/', function ($request, $response) {
|
|
|
|
|
return $response
|
|
|
|
|
->withHeader('Location', '/docs')
|
|
|
|
|
->withStatus(302);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Docs route - serve Swagger UI
|
|
|
|
|
$app->get('/docs', function ($request, $response) {
|
|
|
|
|
$docsPath = __DIR__ . '/docs/index.html';
|
|
|
|
|
|
|
|
|
|
if (!file_exists($docsPath)) {
|
|
|
|
|
return $response
|
|
|
|
|
->withStatus(404)
|
|
|
|
|
->withHeader('Content-Type', 'text/html')
|
|
|
|
|
->getBody()->write('<h1>Documentation not found</h1>');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$html = file_get_contents($docsPath);
|
|
|
|
|
$response->getBody()->write($html);
|
|
|
|
|
|
|
|
|
|
return $response->withHeader('Content-Type', 'text/html');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Serve OpenAPI JSON
|
|
|
|
|
$app->get('/docs/openapi.json', function ($request, $response) {
|
|
|
|
|
$openApiPath = __DIR__ . '/docs/openapi.json';
|
|
|
|
|
|
|
|
|
|
if (!file_exists($openApiPath)) {
|
|
|
|
|
return $response
|
|
|
|
|
->withStatus(404)
|
|
|
|
|
->withHeader('Content-Type', 'application/json')
|
|
|
|
|
->getBody()->write(json_encode(['error' => 'OpenAPI spec not found']));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$json = file_get_contents($openApiPath);
|
|
|
|
|
$response->getBody()->write($json);
|
|
|
|
|
|
|
|
|
|
return $response->withHeader('Content-Type', 'application/json');
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-17 10:43:03 +07:00
|
|
|
// Register module routes
|
|
|
|
|
HealthRoutes::register($app);
|
|
|
|
|
AuthRoutes::register($app);
|
|
|
|
|
RetribusiRoutes::register($app);
|
|
|
|
|
SummaryRoutes::register($app);
|
|
|
|
|
DashboardRoutes::register($app);
|
|
|
|
|
RealtimeRoutes::register($app);
|
|
|
|
|
|
|
|
|
|
// Run application
|
|
|
|
|
$app->run();
|
|
|
|
|
|