forked from Adleraci/adlerka.top
49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
|
|
function runEndpoint($endpoint_file): ?array
|
|
{
|
|
|
|
$endpoint_data = $_POST;
|
|
require_once $endpoint_file;
|
|
|
|
return endpoint($endpoint_data);
|
|
}
|
|
|
|
|
|
function getEndpoint($endpoint_name): string
|
|
{
|
|
$output = array();
|
|
$output["Status"] = "Fail";
|
|
global $routerConfig;
|
|
global $routerRequest;
|
|
|
|
if(!$endpoint_name){
|
|
$endpoint_name = $routerRequest["site_name"];
|
|
}
|
|
|
|
$endpoint_file = $routerConfig["endpoint_dir"] . $endpoint_name . ".php";
|
|
|
|
if (file_exists($endpoint_file)){
|
|
$output_tmp = runEndpoint($endpoint_file);
|
|
$output["Endpoint"] = $endpoint_name;
|
|
switch (gettype($output)) {
|
|
case 'string':
|
|
$output = $output_tmp;
|
|
$output['Status'] = 'Success';
|
|
break;
|
|
case 'bool':
|
|
$output['Status'] = $output ? 'Success' : 'Fail';
|
|
break;
|
|
default:
|
|
$output['Status'] = 'Fail';
|
|
$output["Error"] = "Endpoint error";
|
|
http_response_code(500);
|
|
}
|
|
}
|
|
else{
|
|
$output["Error"] = "Not found";
|
|
http_response_code(404);
|
|
}
|
|
|
|
return json_encode($output);
|
|
} |