Skip to content

Commit

Permalink
🚑 Fix responses always returning 200 on WordPress routes (Fixes #411)…
Browse files Browse the repository at this point in the history
… (#412)
  • Loading branch information
Log1x authored Nov 6, 2024
1 parent b72fd72 commit fca9754
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Roots/Acorn/Application/Concerns/Bootable.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ protected function registerDefaultRoute(): void
$response->header('X-Powered-By', $this->version());
}

$response->setStatusCode(http_response_code());

$content = '';

$levels = ob_get_level();
Expand Down Expand Up @@ -194,13 +196,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 @@ -215,9 +210,15 @@ protected function registerRequestHandler(
return;
}

$config = $this->config->get('router.wordpress', ['web' => 'web', 'api' => 'api']);
if (redirect_canonical(null, false)) {
return;
}

$middleware = Str::startsWith($path, $api)
? $this->config->get('router.wordpress.api', 'api')
: $this->config->get('router.wordpress.web', 'web');

$route->middleware($isApi ? $config['api'] : $config['web']);
$route->middleware($middleware);

ob_start();

Expand Down

0 comments on commit fca9754

Please sign in to comment.