From a00830238460484a90109473d974f6acb87eb121 Mon Sep 17 00:00:00 2001 From: Jacob Casper Date: Sun, 26 Jun 2022 15:19:27 -0500 Subject: [PATCH] Clean up routing code This will help with passing context along to inner pages that need to route based on their own request path context without needing to recalculate it in every route. --- index.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 0928d93..c7b91bc 100644 --- a/index.php +++ b/index.php @@ -2,15 +2,26 @@ // May contain query params $request_uri = explode('?', $_SERVER['REQUEST_URI'], 2); +$pieces = array_values(array_filter( + explode('/', $request_uri[0]), + function($exploded) { return $exploded; } +)); -switch ($request_uri[0]) { - case '/': +if (empty($pieces)) { + require './app.php'; + die; +} + +$path = array_shift($pieces); + +switch ($path) { + case '': require './app.php'; break; - case '/upload': + case 'upload': require './upload.php'; break; - case '/unauthorized': + case 'unauthorized': require './unauthorized.php'; break; default: -- 2.20.1