Clean up routing code
[pics.git] / index.php
index 0928d93..c7b91bc 100644 (file)
--- 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: