File size: 1,512 Bytes
bc63d7d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
// 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';