BlueGit

timfa 66wiki

Files

66wiki / web / dataIndex.php

dataIndex.php

dataIndex.php 1.7 KiB Download Raw
1<?php
2ini_set('display_errors', '1');
3ini_set('display_startup_errors', '1');
4error_reporting(E_ALL);
5
6header('Content-Type: application/json; charset=utf-8');
7header('Access-Control-Allow-Origin: *');
8header('Access-Control-Allow-Methods: GET, HEAD, OPTIONS, POST');
9header('Access-Control-Allow-Headers: *');
10header('X-Robots-Tag: all');
11
12header('X-Content-Type-Options: nosniff');
13header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
14header('Pragma: no-cache');
15
16set_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
28set_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
42require_once __DIR__ . '/dataIndexLib.php';
43
44if (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'];
52header('X-Index-Sha256: ' . $indexSha256);
53
54if (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}