Skip to content

Commit fca9754

Browse files
authored
🚑 Fix responses always returning 200 on WordPress routes (Fixes #411) (#412)
1 parent b72fd72 commit fca9754

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

‎src/Roots/Acorn/Application/Concerns/Bootable.php‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ protected function registerDefaultRoute(): void
156156
$response->header('X-Powered-By', $this->version());
157157
}
158158

159+
$response->setStatusCode(http_response_code());
160+
159161
$content = '';
160162

161163
$levels = ob_get_level();
@@ -194,13 +196,6 @@ protected function registerRequestHandler(
194196
return;
195197
}
196198

197-
if (
198-
$isApi = Str::startsWith($path, $api) &&
199-
redirect_canonical(null, false)
200-
) {
201-
return;
202-
}
203-
204199
add_filter('do_parse_request', function ($condition, $wp, $params) use ($route) {
205200
if (! $route) {
206201
return $condition;
@@ -215,9 +210,15 @@ protected function registerRequestHandler(
215210
return;
216211
}
217212

218-
$config = $this->config->get('router.wordpress', ['web' => 'web', 'api' => 'api']);
213+
if (redirect_canonical(null, false)) {
214+
return;
215+
}
216+
217+
$middleware = Str::startsWith($path, $api)
218+
? $this->config->get('router.wordpress.api', 'api')
219+
: $this->config->get('router.wordpress.web', 'web');
219220

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

222223
ob_start();
223224

0 commit comments

Comments
 (0)