|
18 | 18 | * |
19 | 19 | * @var string |
20 | 20 | */ |
21 | | -define('MPG_APP_VERSION', '1.1.2'); |
| 21 | +define('MPG_APP_VERSION', '1.1.3'); |
22 | 22 |
|
23 | 23 | /** |
24 | 24 | * Development mode? |
|
31 | 31 | * Absolute path. XXX Without trailing slash. |
32 | 32 | * |
33 | 33 | * @var string |
| 34 | + * @example /opt/mongodb-php-gui |
34 | 35 | */ |
35 | 36 | define('MPG_ABS_PATH', __DIR__); |
36 | 37 |
|
37 | 38 | $baseUrl = '//' . $_SERVER['HTTP_HOST']; |
38 | | -$serverPath = str_replace('\\', '/', dirname($_SERVER['REQUEST_URI'])); |
39 | | -$serverPath = ( $serverPath === '/' ) ? '' : $serverPath; |
| 39 | + |
| 40 | +// If request matches a folder. For example: /mongo/ |
| 41 | +if ( preg_match('#/$#', $_SERVER['REQUEST_URI']) ) { |
| 42 | + |
| 43 | + $serverPath = $_SERVER['REQUEST_URI']; |
| 44 | + |
| 45 | +} else { |
| 46 | + |
| 47 | + $serverPath = dirname($_SERVER['REQUEST_URI']); |
| 48 | + |
| 49 | + // Normalize directory separator in server path. |
| 50 | + if ( DIRECTORY_SEPARATOR !== '/' ) { |
| 51 | + $serverPath = str_replace(DIRECTORY_SEPARATOR, '/', $serverPath); |
| 52 | + } |
| 53 | + |
| 54 | +} |
| 55 | + |
| 56 | +$serverPath = rtrim($serverPath, '/'); |
| 57 | + |
40 | 58 | $baseUrl .= $serverPath; |
41 | 59 |
|
42 | 60 | /** |
43 | 61 | * Server path. XXX Without trailing slash. |
44 | 62 | * |
45 | 63 | * @var string |
| 64 | + * @example /mongo |
46 | 65 | */ |
47 | 66 | define('MPG_SERVER_PATH', $serverPath); |
48 | 67 |
|
49 | 68 | /** |
50 | 69 | * Base URL. XXX Without trailing slash. |
51 | 70 | * |
52 | 71 | * @var string |
| 72 | + * @example http://127.0.0.1:5000/mongo |
53 | 73 | */ |
54 | 74 | define('MPG_BASE_URL', $baseUrl); |
55 | 75 |
|
56 | | -require __DIR__ . '/autoload.php'; |
57 | | -require __DIR__ . '/routes.php'; |
| 76 | +require MPG_ABS_PATH . '/autoload.php'; |
| 77 | +require MPG_ABS_PATH . '/routes.php'; |
58 | 78 |
|
59 | 79 | $application = new Application($router); |
60 | 80 | $serverRequest = ServerRequestFactory::createFromGlobals(); |
61 | 81 |
|
62 | | -// XXX This hack makes index to work in sub-folder case. |
63 | 82 | try { |
64 | 83 | $response = $application->dispatch($serverRequest); |
65 | 84 | } catch (NotFoundHttpException $e) { |
66 | | - header('Location: ' . rtrim($_SERVER['REQUEST_URI'], '/') . '/index'); |
| 85 | + die('Route not found. Try to append a slash to URL.'); |
67 | 86 | } |
68 | 87 |
|
69 | 88 | $application->send($response); |
0 commit comments