![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/brickabois.com/private_html/api/ |
<?php
/**
* Free Village Network - API Entry Point
* RESTful API for The Commons, The Ledger, and The Land
*/
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
// Handle preflight requests
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit;
}
// Load configuration
require_once dirname(__DIR__) . '/../private_html/config.php';
// Simple router
$request_uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$request_method = $_SERVER['REQUEST_METHOD'];
$path_parts = explode('/', trim($request_uri, '/'));
// Remove 'api' from path
if ($path_parts[0] === 'api') {
array_shift($path_parts);
}
// Route handling
$endpoint = $path_parts[0] ?? 'index';
$action = $path_parts[1] ?? null;
$id = $path_parts[2] ?? null;
// Response helper
function jsonResponse($data, $status = 200) {
http_response_code($status);
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
exit;
}
function errorResponse($message, $status = 400) {
jsonResponse(['error' => $message], $status);
}
// API Routes
try {
switch ($endpoint) {
case 'index':
case '':
jsonResponse([
'name' => 'Free Village Network API',
'version' => '1.0.0',
'dimensions' => [
'commons' => '/api/commons',
'ledger' => '/api/ledger',
'land' => '/api/land'
],
'endpoints' => [
'GET /api' => 'API information',
'GET /api/commons/posts' => 'Get posts feed',
'GET /api/commons/events' => 'Get events',
'GET /api/land/villages' => 'Get villages',
'GET /api/ledger/proposals' => 'Get proposals'
]
]);
break;
case 'commons':
require_once __DIR__ . '/endpoints/commons.php';
break;
case 'ledger':
require_once __DIR__ . '/endpoints/ledger.php';
break;
case 'land':
require_once __DIR__ . '/endpoints/land.php';
break;
case 'auth':
require_once __DIR__ . '/endpoints/auth.php';
break;
case 'map':
require_once __DIR__ . '/endpoints/map.php';
break;
default:
errorResponse('Endpoint not found', 404);
}
} catch (Exception $e) {
error_log("API Error: " . $e->getMessage());
errorResponse('Internal server error', 500);
}