Skip to content

Commit f173d78

Browse files
committed
feat: Add API-Endpoints (like /check/{domain})
1 parent 6ede930 commit f173d78

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

config.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
return [
4-
'version' => '2.2.3',
4+
'version' => '3.0.0',
55

66
'domains' => [
77
'mtex.dev',
@@ -12,6 +12,9 @@
1212
'diff.mtex.dev',
1313
'github.mtex.dev',
1414
'index.mtex.dev',
15+
'gh.mtex.dev',
16+
17+
//'go.mtex.dev',
1518

1619
'gimy.site',
1720
'getmy.name',

index.php

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,65 @@
44
$version = $config['version'];
55

66
$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) {
815
header('Content-Type: application/json; charset=utf-8');
916
echo json_encode([
1017
'version' => $version,
1118
'domains' => $domains,
1219
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
1320
exit;
1421
}
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+
}
1566
?>
1667
<!DOCTYPE html>
1768
<html lang="en">

0 commit comments

Comments
 (0)