37 lines
1.0 KiB
PHP
37 lines
1.0 KiB
PHP
<?php
|
|
/**
|
|
* Simple Router & Entry Point
|
|
*/
|
|
|
|
require_once __DIR__ . '/../app/bootstrap/init.php';
|
|
|
|
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
|
$route = $_GET['route'] ?? str_replace('/api/', '', $uri);
|
|
$route = trim($route, '/');
|
|
|
|
// Mapping routes to modules
|
|
$routes = [
|
|
'auth/login' => 'auth/login.php',
|
|
'auth/refresh' => 'auth/refresh.php',
|
|
'auth/logout' => 'auth/logout.php',
|
|
'users' => 'users/index.php',
|
|
'trips' => 'trips/index.php',
|
|
];
|
|
|
|
if (isset($routes[$route])) {
|
|
$file = APP_PATH . '/modules_app/' . $routes[$route];
|
|
if (file_exists($file)) {
|
|
require_once $file;
|
|
} else {
|
|
json_error("Endpoint file missing: {$route}", 500);
|
|
}
|
|
} else {
|
|
// If no route matches, maybe it's a SPA request or 404
|
|
if (str_starts_with($route, 'v1/')) {
|
|
json_error("Not Found: {$route}", 404);
|
|
} else {
|
|
// Fallback for non-API requests (Frontend)
|
|
echo "<h1>Musadaq API - Pure PHP</h1><p>Running on simple architecture.</p>";
|
|
}
|
|
}
|