41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
/**
|
|
* Simple Router & Entry Point
|
|
*/
|
|
|
|
require_once __DIR__ . '/../app/bootstrap/init.php';
|
|
|
|
// Global Request Logging (for debugging on server)
|
|
error_log("Incoming Request: " . ($_SERVER['REQUEST_METHOD'] ?? 'GET') . " " . ($_SERVER['REQUEST_URI'] ?? '/'));
|
|
|
|
$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 {
|
|
// Not an API request — serve the SPA shell
|
|
include __DIR__ . '/shell.php';
|
|
exit;
|
|
}
|
|
}
|