diff --git a/features/server.feature b/features/server.feature index 6c71ec8..57368a6 100644 --- a/features/server.feature +++ b/features/server.feature @@ -132,3 +132,23 @@ Feature: Serve WordPress locally """ 1338 """ + + Scenario: Respond with a 404 for a missing file in a directory without an index.php + Given an empty directory + And a static.txt file: + """ + Static content + """ + And I launch in the background `wp server --host=localhost --port=8189 --docroot=.` + + When I run `curl -sS http://localhost:8189/static.txt` + Then STDOUT should contain: + """ + Static content + """ + + When I run `curl -sS -o /dev/null -w '%{http_code}' http://localhost:8189/missing.zip` + Then STDOUT should be: + """ + 404 + """ diff --git a/router.php b/router.php index 2db7738..9284da1 100644 --- a/router.php +++ b/router.php @@ -153,6 +153,9 @@ static function ( $buffer ) { } else { return false; } +} elseif ( ! is_file( $wpcli_server_root . DIRECTORY_SEPARATOR . 'index.php' ) ) { + // Without an index.php to route to, let the built-in web server respond with a 404. + return false; } else { // File doesn't exist or is outside document root - route to index.php for pretty permalinks $_SERVER['SCRIPT_NAME'] = '/index.php';