| 1 | <?php |
| 2 | ini_set('display_errors', '1'); |
| 3 | ini_set('display_startup_errors', '1'); |
| 4 | error_reporting(E_ALL); |
| 5 | |
| 6 | header('Content-Type: application/json; charset=utf-8'); |
| 7 | header('Access-Control-Allow-Origin: *'); |
| 8 | header('Access-Control-Allow-Methods: GET, HEAD, OPTIONS, POST'); |
| 9 | header('Access-Control-Allow-Headers: *'); |
| 10 | header('X-Robots-Tag: all'); |
| 11 | |
| 12 | header('X-Content-Type-Options: nosniff'); |
| 13 | header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); |
| 14 | header('Pragma: no-cache'); |
| 15 | |
| 16 | set_error_handler(function ($severity, $message, $file, $line) { |
| 17 | http_response_code(500); |
| 18 | echo json_encode([ |
| 19 | 'error' => 'PHP Error', |
| 20 | 'severity' => $severity, |
| 21 | 'message' => $message, |
| 22 | 'file' => $file, |
| 23 | 'line' => $line, |
| 24 | ], JSON_PRETTY_PRINT); |
| 25 | exit; |
| 26 | }); |
| 27 | |
| 28 | set_exception_handler(function ($e) { |
| 29 | http_response_code(500); |
| 30 | echo json_encode([ |
| 31 | 'error' => 'Uncaught Exception', |
| 32 | 'type' => get_class($e), |
| 33 | 'message' => $e->getMessage(), |
| 34 | 'file' => $e->getFile(), |
| 35 | 'line' => $e->getLine(), |
| 36 | 'trace' => explode("\n", $e->getTraceAsString()), |
| 37 | ], JSON_PRETTY_PRINT); |
| 38 | exit; |
| 39 | }); |
| 40 | |
| 41 | |
| 42 | require_once __DIR__ . '/dataIndexLib.php'; |
| 43 | |
| 44 | if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'OPTIONS') { |
| 45 | http_response_code(204); |
| 46 | exit; |
| 47 | } |
| 48 | |
| 49 | $built = buildDataIndex(); |
| 50 | $index = $built['nodes']; |
| 51 | $indexSha256 = $built['indexSha256']; |
| 52 | header('X-Index-Sha256: ' . $indexSha256); |
| 53 | |
| 54 | if (isset($_GET['meta'])) { |
| 55 | // Opt-in wrapper; the default output stays the plain node list. |
| 56 | echo json_encode([ |
| 57 | 'indexSha256' => $indexSha256, |
| 58 | 'nodes' => $index, |
| 59 | ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
| 60 | } else { |
| 61 | echo json_encode($index, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
| 62 | } |