Ensured the health action is registered bit with and without version

This commit is contained in:
Alejandro Celaya 2020-01-06 23:32:43 +01:00
parent 96eb6a80e1
commit 36d5e057d0
3 changed files with 12 additions and 6 deletions

View file

@ -12,6 +12,7 @@ return [
'routes_whitelist' => [
Action\HealthAction::class,
Action\ShortUrl\SingleStepCreateShortUrlAction::class,
ConfigProvider::UNVERSIONED_HEALTH_ENDPOINT_NAME,
],
'plugins' => [

View file

@ -13,6 +13,7 @@ class ConfigProvider
{
private const ROUTES_PREFIX = '/rest/v{version:1|2}';
private const UNVERSIONED_ROUTES_PREFIX = '/rest';
public const UNVERSIONED_HEALTH_ENDPOINT_NAME = 'unversioned_health';
private Closure $loadConfig;
@ -34,11 +35,14 @@ class ConfigProvider
// Prepend the routes prefix to every path
foreach ($routes as $key => $route) {
['path' => $path] = $route;
$routes[$key]['path'] = sprintf(
'%s%s',
$path === '/health' ? self::UNVERSIONED_ROUTES_PREFIX : self::ROUTES_PREFIX,
$path,
);
$routes[$key]['path'] = sprintf('%s%s', self::ROUTES_PREFIX, $path);
// Also append the health route so that it works without version
if ($path === '/health') {
$route['path'] = sprintf('%s%s', self::UNVERSIONED_ROUTES_PREFIX, $path);
$route['name'] = self::UNVERSIONED_HEALTH_ENDPOINT_NAME;
$routes[] = $route;
}
}
return $config;

View file

@ -43,7 +43,8 @@ class ConfigProviderTest extends TestCase
['path' => '/rest/v{version:1|2}/foo'],
['path' => '/rest/v{version:1|2}/bar'],
['path' => '/rest/v{version:1|2}/baz/foo'],
['path' => '/rest/health'],
['path' => '/rest/v{version:1|2}/health'],
['path' => '/rest/health', 'name' => ConfigProvider::UNVERSIONED_HEALTH_ENDPOINT_NAME],
], $config['routes']);
}
}