setBasePath('/admin'); // Auth check middleware $router->before('GET', '/(.*)', function ($path) { // ignore /admin and /auth if ($path === '' || strpos($path, 'auth') === 0) { return; } // for any other URLs, if not auth'd, redirec to /admin if (!isset($_SESSION['auth'])) { header('location: /admin'); exit(); } }); // Redirect 404s $router->set404(function () { header('HTTP/1.1 404 Not Found'); require_once 'pages/admin.php'; }); // Index $router->get("/", function () { require_once 'pages/admin.php'; }); // Site update $router->get("/update", function () { require_once 'pages/update.php'; }); // Log $router->get("/logs/{file}", function ($file) { if (file_exists("logs/$file") && $file !== '.gitignore') { $log = file_get_contents("logs/$file"); } else { $log = "File $file not found"; } require_once 'pages/log.php'; }); // Auth routes $router->mount('/auth', function () use ($router) { // Login $router->get("/login", function () { require_once 'pages/auth/login.php'; }); // Logout $router->get("/logout", function () { require_once 'pages/auth/logout.php'; }); }); $router->run();