- Add source maps and license files for compiled assets - Add debug and test files for development - Complete Git repository with all necessary files for MoneyFlix project
130 lines
4.5 KiB
PHP
130 lines
4.5 KiB
PHP
<?php
|
|
/**
|
|
* BitReport CRM - Sistema de Rotas Global
|
|
*
|
|
* ⚠️ ATENÇÃO: Este ficheiro serve apenas para rotas de SISTEMA.
|
|
*
|
|
* - Rotas de funcionalidades (dashboards, apps, páginas, APIs de negócio, etc.) DEVEM ser definidas nos respetivos módulos em Modules/<Modulo>/Routes/web.php
|
|
* - Só devem existir aqui rotas de sistema, healthcheck, ferramentas internas ou fallback 404.
|
|
* - Qualquer exceção deve ser justificada e documentada.
|
|
*
|
|
* Exemplo de rotas permitidas aqui:
|
|
* - Carregamento automático dos módulos
|
|
* - Rota de healthcheck
|
|
* - Fallback 404
|
|
* - Ferramentas administrativas globais
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
use App\Core\Router;
|
|
use App\Core\View;
|
|
|
|
// Register pages namespace
|
|
View::addNamespace('pages', __DIR__ . '/../Modules/Views');
|
|
|
|
// Load pages routes
|
|
require_once __DIR__ . '/../Modules/Routes/web.php';
|
|
|
|
// --- Module Loader ---
|
|
$modulesDir = __DIR__ . '/../Modules';
|
|
$moduleFolders = scandir($modulesDir);
|
|
foreach ($moduleFolders as $moduleName) {
|
|
if ($moduleName[0] === '.') continue;
|
|
$modulePath = $modulesDir . '/' . $moduleName;
|
|
if (is_dir($modulePath)) {
|
|
// Register views namespace
|
|
if (is_dir($viewPath = $modulePath . '/Views')) {
|
|
View::addNamespace(strtolower($moduleName), $viewPath);
|
|
}
|
|
|
|
// Load routes
|
|
if (file_exists($routesPath = $modulePath . '/Routes/web.php')) {
|
|
require_once $routesPath;
|
|
}
|
|
if (file_exists($apiRoutesPath = $modulePath . '/Routes/api.php')) {
|
|
require_once $apiRoutesPath;
|
|
}
|
|
if (file_exists($publicRoutesPath = $modulePath . '/Routes/public.php')) {
|
|
require_once $publicRoutesPath;
|
|
}
|
|
|
|
// Auto-register module widgets if widgets.php exists
|
|
// TEMPORARILY DISABLED - causing memory issues
|
|
// if (file_exists($widgetsPath = $modulePath . '/widgets.php')) {
|
|
// require_once $widgetsPath;
|
|
// }
|
|
}
|
|
}
|
|
|
|
$router = Router::getInstance();
|
|
|
|
// --- HOME ROUTE ---
|
|
// Redirect to login if not authenticated, otherwise to redirects dashboard
|
|
$router->get('/', function() {
|
|
if (!\App\Core\Auth::check()) {
|
|
header('Location: /auth/login');
|
|
exit();
|
|
}
|
|
header('Location: /redirects');
|
|
exit();
|
|
});
|
|
|
|
// --- DASHBOARD ROUTE ---
|
|
// Protect /dashboard route - require authentication
|
|
$router->get('/dashboard', function() {
|
|
if (!\App\Core\Auth::check()) {
|
|
header('Location: /auth/login');
|
|
exit();
|
|
}
|
|
header('Location: /redirects');
|
|
exit();
|
|
});
|
|
|
|
|
|
|
|
|
|
// System status redirects
|
|
$router->get('/system/status', function() {
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['status' => 'OK', 'timestamp' => date('c')]);
|
|
exit;
|
|
});
|
|
|
|
// --- Dashboard API Routes ---
|
|
$router->get('/api/dashboard/stats', [App\Api\DashboardController::class, 'stats']);
|
|
$router->get('/api/dashboard/available-widgets', [App\Api\DashboardController::class, 'getAvailableWidgets']);
|
|
$router->get('/api/dashboard/user-widgets', [App\Api\DashboardController::class, 'getUserWidgets']);
|
|
$router->post('/api/dashboard/add-widget', [App\Api\DashboardController::class, 'addWidget']);
|
|
$router->post('/api/dashboard/remove-widget', [App\Api\DashboardController::class, 'removeWidget']);
|
|
$router->post('/api/dashboard/update-widget-order', [App\Api\DashboardController::class, 'updateWidgetOrder']);
|
|
$router->post('/api/dashboard/update-widget-config', [App\Api\DashboardController::class, 'updateWidgetConfig']);
|
|
|
|
// --- Log Processor API Routes ---
|
|
$router->post('/api/log-processor/process-logs', [App\Api\LogProcessorController::class, 'processLogs']);
|
|
$router->post('/api/log-processor/process-file', [App\Api\LogProcessorController::class, 'processFile']);
|
|
$router->get('/api/log-processor/stats', [App\Api\LogProcessorController::class, 'getStats']);
|
|
|
|
|
|
|
|
// --- Ferramentas internas ---
|
|
$router->get('/tools/mb-search', function() {
|
|
require __DIR__ . '/../Views/pages/public/mb-search.php';
|
|
});
|
|
|
|
// --- Public Campaign Analytics Routes ---
|
|
$router->get('/public/analytics/{slug}', [App\Modules\Controllers\PublicCampaignsController::class, 'analytics']);
|
|
$router->get('/api/campaigns/{slug}', [App\Modules\Controllers\PublicCampaignsController::class, 'getCampaignStats']);
|
|
|
|
// --- Catch-all 404 Route (MUST BE LAST!) ---
|
|
$router->get('/{path}', function (
|
|
$path
|
|
) {
|
|
http_response_code(404);
|
|
View::render('@pages/404', [
|
|
'title' => '404 Error - Page not found',
|
|
'page_content' => function() use ($path) {
|
|
View::render('components/404.php', ['page' => $path]);
|
|
}
|
|
]);
|
|
});
|