From ab2b0ac1a0de3b61b85f541093726cdce9920637 Mon Sep 17 00:00:00 2001 From: QWp6t Date: Wed, 6 Nov 2024 14:29:59 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20Fix=20responses=20always=20retur?= =?UTF-8?q?ning=20200=20on=20WordPress=20routes=20(#412)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/Bootloader.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index 55346353..2d5d586b 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -218,6 +218,8 @@ protected function registerDefaultRoute(): void $response->header('X-Powered-By', $this->app->version()); } + $response->setStatusCode(http_response_code()); + $content = ''; $levels = ob_get_level(); @@ -257,13 +259,6 @@ protected function registerRequestHandler( return; } - if ( - $isApi = Str::startsWith($path, $api) && - redirect_canonical(null, false) - ) { - return; - } - add_filter('do_parse_request', function ($condition, $wp, $params) use ($route) { if (! $route) { return $condition; @@ -282,9 +277,15 @@ protected function registerRequestHandler( return; } - $config = $this->app->config->get('router.wordpress', ['web' => 'web', 'api' => 'api']); + if (redirect_canonical(null, false)) { + return; + } + + $middleware = Str::startsWith($path, $api) + ? $this->app->config->get('router.wordpress.api', 'api') + : $this->app->config->get('router.wordpress.web', 'web'); - $route->middleware($isApi ? $config['api'] : $config['web']); + $route->middleware($middleware); ob_start();