|
4 | 4 | $version = $config['version']; |
5 | 5 |
|
6 | 6 | $requestUri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); |
7 | | -if ($requestUri === '/json' || $requestUri === '/json/' || $requestUri === '/index.php/json' || $requestUri === '/index.php/json/' || (isset($_GET['format']) && $_GET['format'] === 'json') || (isset($_GET['output']) && $_GET['output'] === 'json') || (isset($_GET['type']) && $_GET['type'] === 'json') || (isset($_GET['type']) && $_GET['type'] === 'raw')) { |
| 7 | +$scriptName = $_SERVER['SCRIPT_NAME']; |
| 8 | +$path = str_replace($scriptName, '', $requestUri); |
| 9 | +$path = trim($path, '/'); |
| 10 | +$parts = explode('/', $path); |
| 11 | + |
| 12 | +$isLegacyJson = in_array($path, ['json', 'index.php/json']) || (isset($_GET['format']) && $_GET['format'] === 'json') || (isset($_GET['output']) && $_GET['output'] === 'json') || (isset($_GET['type']) && ($_GET['type'] === 'json' || $_GET['type'] === 'raw')); |
| 13 | + |
| 14 | +if ($isLegacyJson) { |
8 | 15 | header('Content-Type: application/json; charset=utf-8'); |
9 | 16 | echo json_encode([ |
10 | 17 | 'version' => $version, |
11 | 18 | 'domains' => $domains, |
12 | 19 | ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
13 | 20 | exit; |
14 | 21 | } |
| 22 | + |
| 23 | +if (isset($parts[0]) && $parts[0] === 'api') { |
| 24 | + header('Content-Type: application/json; charset=utf-8'); |
| 25 | + |
| 26 | + $action = $parts[1] ?? null; |
| 27 | + |
| 28 | + switch ($action) { |
| 29 | + case 'domains': |
| 30 | + echo json_encode([ |
| 31 | + 'status' => 'success', |
| 32 | + 'version' => $version, |
| 33 | + 'domains' => $domains |
| 34 | + ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
| 35 | + break; |
| 36 | + |
| 37 | + case 'check': |
| 38 | + $targetDomain = $parts[2] ?? null; |
| 39 | + if (!$targetDomain) { |
| 40 | + http_response_code(400); |
| 41 | + echo json_encode(['error' => 'No domain specified. Usage: /api/check/example.com']); |
| 42 | + } else { |
| 43 | + $exists = in_array($targetDomain, $domains); |
| 44 | + echo json_encode([ |
| 45 | + 'domain' => $targetDomain, |
| 46 | + 'exists' => $exists, |
| 47 | + 'message' => $exists ? 'Domain is registered.' : 'Domain not found.' |
| 48 | + ], JSON_PRETTY_PRINT); |
| 49 | + } |
| 50 | + break; |
| 51 | + |
| 52 | + default: |
| 53 | + echo json_encode([ |
| 54 | + 'message' => 'index.MTEX.dev API', |
| 55 | + 'version' => $version, |
| 56 | + 'available_functions' => [ |
| 57 | + '/api/domains' => 'Returns a list of all registered domains.', |
| 58 | + '/api/check/{domain}' => 'Checks if a specific domain exists in the directory.', |
| 59 | + '/json' => 'Legacy endpoint for domain manifest.' |
| 60 | + ] |
| 61 | + ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
| 62 | + break; |
| 63 | + } |
| 64 | + exit; |
| 65 | +} |
15 | 66 | ?> |
16 | 67 | <!DOCTYPE html> |
17 | 68 | <html lang="en"> |
|
0 commit comments