diff --git a/public/index.php b/public/index.php index fb34207..efdf27e 100644 --- a/public/index.php +++ b/public/index.php @@ -4,16 +4,16 @@ const SERVER = '../server'; require_once SERVER.'/bootstrap.php'; -// check if the server has been installed -if (!installed()) redirect('/install'); - -// spin up our app container +// spin up our app container and the initial route $app = new App(DB); - -// route the request -// routing follows a simple rule; the first segment of the URI is the -// module, and the module handles the rest $route = App::$req->uri(0); -$routes = [ - 'home' => 'HomeModule::home', -]; + +// redirect depending on installation status +installRedirect($route); + +if ($route == '/') return HomeModule::home(); +if ($route == '/install') return InstallModule::handle(); + +// 404 +http_response_code(404); +echo '404: ' . $route; diff --git a/server/app/app.php b/server/app/app.php index 77e986e..74f73eb 100644 --- a/server/app/app.php +++ b/server/app/app.php @@ -14,18 +14,4 @@ class App self::$req = new Request(); // the current request self::$db = new Database($dbPath); // the database } - - public function route(string $uri, array $routes) - { - // check if the module exists - if (isset($routes[$module])) { - // if the module exists, call the module's handle method - $routes[$module]($this); - } else { - // if the module does not exist, render a 404 page - $this->render('404', [ - 'title' => '404', - ]); - } - } } diff --git a/server/bootstrap.php b/server/bootstrap.php index 79c3823..0dfed75 100644 --- a/server/bootstrap.php +++ b/server/bootstrap.php @@ -15,6 +15,9 @@ const DB = SERVER.'/database/dragon.db'; require_once SERVER.'/library.php'; // include our miscellaneous functions +// define whether we are installed or not +define('INSTALLED', file_exists(SERVER.'/.installed')); + // autoloader map const MAP = [ // 'Class' => 'path/to/class.php', diff --git a/server/library.php b/server/library.php index 0d5c9a7..7066cb6 100644 --- a/server/library.php +++ b/server/library.php @@ -1,33 +1,22 @@ uri(0); } } diff --git a/server/modules/InstallModule.php b/server/modules/InstallModule.php new file mode 100644 index 0000000..e69de29