From 81670044f316d1887d90bdb8ae03e3e9d6b8fba7 Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Wed, 17 Jul 2024 22:18:55 -0500 Subject: [PATCH] Fix bootstrap location, fix routes --- public/index.php | 6 +++--- server/app/App.php | 15 ++++++++------- server/modules/GateModule.php | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/public/index.php b/public/index.php index 5129564..5672b19 100644 --- a/public/index.php +++ b/public/index.php @@ -4,7 +4,7 @@ // define our server path and bootstrap the request const SERVER = '../server'; -require_once SERVER.'/bootstrap/Boot.php'; +require_once SERVER.'/boot/Boot.php'; // spin up our app container and the initial route $app = new App(new Database(DB), new Request(), new Auth()); @@ -15,7 +15,7 @@ installRedirect($route); // route to the relevant module $app->route('/', 'HomeModule') - ->route('/install', 'InstallModule') - ->route('/gate', 'GateModule') + ->route('install', 'InstallModule') + ->route('gate', 'GateModule') ->handle($route) ->cleanup(); diff --git a/server/app/App.php b/server/app/App.php index 3e50706..18ffea6 100644 --- a/server/app/App.php +++ b/server/app/App.php @@ -45,7 +45,14 @@ class App public function handle(string $uri): App { - if (!isset($this->routes[$uri])) return self::fourOhFour($uri); + // if the route doesn't exist, return 404 + if (!isset($this->routes[$uri])) { + http_response_code(404); + echo "404: $uri"; + return $this; + } + + // handle the route $this->routes[$uri]::handle(); return $this; } @@ -68,10 +75,4 @@ class App $_SESSION['flash'] = []; self::$flashes = []; } - - public static function fourOhFour(string $uri): void - { - http_response_code(404); - echo "404: $uri"; - } } diff --git a/server/modules/GateModule.php b/server/modules/GateModule.php index 962b986..854b3c4 100644 --- a/server/modules/GateModule.php +++ b/server/modules/GateModule.php @@ -9,7 +9,7 @@ class GateModule $s = App::$req->uri(1) ?? ''; // second segment $m = App::$req->method; // request method - if (App::$auth->good() && in_array($s, self::GUEST)) redirect('/'); + if (App::auth() && in_array($s, self::GUEST)) redirect('/'); if ($s == '' || $s == 'login') return self::login($m); if ($s == 'logout' && $m == 'POST') return self::logout();