From: Jacob Casper Date: Sun, 26 Jun 2022 20:19:27 +0000 (-0500) Subject: Clean up routing code X-Git-Url: https://git.jacobcasper.com/?p=pics.git;a=commitdiff_plain;h=a00830238460484a90109473d974f6acb87eb121 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. --- 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: