diff options
Diffstat (limited to 'api/_main.php')
-rw-r--r-- | api/_main.php | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/api/_main.php b/api/_main.php new file mode 100644 index 0000000..215c1b2 --- /dev/null +++ b/api/_main.php @@ -0,0 +1,30 @@ +<?php + +if (str_ends_with($_GET['_'], "/")) { + $pagename = substr($_GET['_'], 0, strlen($_GET['_']) - 1); +} else { + $pagename = $_GET['_']; +} + +$toplevel = explode("/", $pagename)[1]; +$middlelevel = explode("/", $pagename)[2] ?? null; + +if ($toplevel === "_main" || $middlelevel === "_main") { + header("HTTP/1.1 404 Not Found"); + header("Content-Type: text/plain"); + echo("Endpoint not found"); + die(); +} + +if (isset($middlelevel) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/api/" . $toplevel . "/" . $middlelevel . ".php") && is_file($_SERVER['DOCUMENT_ROOT'] . "/api/" . $toplevel . "/" . $middlelevel . ".php")) { + require_once $_SERVER['DOCUMENT_ROOT'] . "/api/" . $toplevel . "/" . $middlelevel . ".php"; +} else { + if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/api/" . $toplevel . ".php") && is_file($_SERVER['DOCUMENT_ROOT'] . "/api/" . $toplevel . ".php")) { + require_once $_SERVER['DOCUMENT_ROOT'] . "/api/" . $toplevel . ".php"; + } else { + header("HTTP/1.1 404 Not Found"); + header("Content-Type: text/plain"); + echo("Endpoint not found"); + die(); + } +} |