Skip to content

Commit

Permalink
🚑 Fix responses always returning 200 on WordPress routes (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
QWp6t committed Nov 6, 2024
1 parent ede407b commit ab2b0ac
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Roots/Acorn/Bootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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();

Expand Down

0 comments on commit ab2b0ac

Please sign in to comment.