├── includes ├── 400.php ├── 404.php └── 500.php ├── index.php └── readme.md /includes/400.php: -------------------------------------------------------------------------------- 1 | 400 bad request 2 | -------------------------------------------------------------------------------- /includes/404.php: -------------------------------------------------------------------------------- 1 | 404 not found 2 | -------------------------------------------------------------------------------- /includes/500.php: -------------------------------------------------------------------------------- 1 | 500 server error 2 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 19 | // 20 | // 21 | // hello world 22 | // 23 | // 24 | // HTML; 25 | // } else { 26 | // include(__DIR__ . '/includes/404.php'); 27 | // } 28 | 29 | // if ($requestMethod === 'GET' and $requestPath === '/') { 30 | // print << 32 | // 33 | // 34 | // hello world 35 | // 36 | // 37 | // HTML; 38 | // } else if ($requestPath === '/old-home') { 39 | // header('Location: /', $replace = true, $code = 301); 40 | // exit; 41 | // } else { 42 | // include(__DIR__ . '/includes/404.php'); 43 | // } 44 | 45 | function redirectForeverTo($path) { 46 | header("Location: {$path}", $replace = true, $code = 301); 47 | exit; 48 | } 49 | 50 | // if ($requestMethod === 'GET' and $requestPath === '/') { 51 | // print << 53 | // 54 | // 55 | // hello world 56 | // 57 | // 58 | // HTML; 59 | // } else if ($requestPath === '/old-home') { 60 | // redirectForeverTo('/'); 61 | // } else { 62 | // include(__DIR__ . '/includes/404.php'); 63 | // } 64 | 65 | $routes = [ 66 | 'GET' => [ 67 | '/' => fn() => print 68 | << 70 | 71 | 72 | hello world 73 | 74 | 75 | HTML, 76 | '/old-home' => fn() => redirectForeverTo('/'), 77 | '/has-server-error' => fn() => throw new Exception(), 78 | '/has-validation-error' => fn() => abort(400), 79 | ], 80 | 'POST' => [], 81 | 'PATCH' => [], 82 | 'PUT' => [], 83 | 'DELETE' => [], 84 | 'HEAD' => [], 85 | '404' => fn() => include(__DIR__ . '/includes/404.php'), 86 | '400' => fn() => include(__DIR__ . '/includes/400.php'), 87 | '500' => fn() => include(__DIR__ . '/includes/500.php'), 88 | ]; 89 | 90 | $paths = array_merge( 91 | array_keys($routes['GET']), 92 | array_keys($routes['POST']), 93 | array_keys($routes['PATCH']), 94 | array_keys($routes['PUT']), 95 | array_keys($routes['DELETE']), 96 | array_keys($routes['HEAD']), 97 | ); 98 | 99 | function abort($code) { 100 | global $routes; 101 | $routes[$code](); 102 | } 103 | 104 | set_error_handler(function() { 105 | abort(500); 106 | }); 107 | 108 | 109 | set_exception_handler(function() { 110 | abort(500); 111 | }); 112 | 113 | if (isset( 114 | $routes[$requestMethod], 115 | $routes[$requestMethod][$requestPath], 116 | )) { 117 | $routes[$requestMethod][$requestPath](); 118 | } else if (in_array($requestPath, $paths)) { 119 | abort(400); 120 | } else { 121 | abort(404); 122 | } 123 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Whoosh website 2 | 3 | To run the local development server, try: 4 | 5 | ``` 6 | export PHP_ENV=prod && php -S 127.0.0.1:8000 -t . 7 | ``` 8 | 9 | To make requests with cURL, try: 10 | 11 | ``` 12 | curl -X DELETE http://127.0.0.1:8000/old-home 13 | ``` 14 | --------------------------------------------------------------------------------