| // Simple router to handle /health and /api-docs, and otherwise delegate to Matomo's index.php or static files. | |
| $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); | |
| if ($uri === '/health') { | |
| header('Content-Type: application/json'); | |
| echo json_encode(['status' => 'healthy', 'app' => 'matomo']); | |
| exit; | |
| } | |
| if ($uri === '/api-docs') { | |
| header('Content-Type: application/json'); | |
| echo json_encode([ | |
| 'openapi' => '3.0.0', | |
| 'info' => [ | |
| 'title' => 'Matomo Hugging Face API', | |
| 'version' => '1.0.0' | |
| ], | |
| 'paths' => [ | |
| '/health' => [ | |
| 'get' => [ | |
| 'summary' => 'Health check', | |
| 'responses' => [ | |
| '200' => [ | |
| 'description' => 'App is healthy' | |
| ] | |
| ] | |
| ] | |
| ], | |
| '/api-docs' => [ | |
| 'get' => [ | |
| 'summary' => 'API Documentation', | |
| 'responses' => [ | |
| '200' => [ | |
| 'description' => 'API Schema' | |
| ] | |
| ] | |
| ] | |
| ] | |
| ] | |
| ]); | |
| exit; | |
| } | |
| // Serve static files directly if they exist | |
| $file = __DIR__ . $uri; | |
| if ($uri !== '/' && file_exists($file) && !is_dir($file)) { | |
| // Let PHP server handle static file | |
| return false; | |
| } | |
| // Fallback to index.php | |
| require_once __DIR__ . '/index.php'; | |