From 7cc8c023fa31338041aa7803f23349d306d35201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Fri, 15 Mar 2024 16:14:05 +0100 Subject: [PATCH] use http_client() from castor --- .castor/docker.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.castor/docker.php b/.castor/docker.php index f9e7121..c095119 100644 --- a/.castor/docker.php +++ b/.castor/docker.php @@ -6,6 +6,7 @@ use Castor\Attribute\AsOption; use Castor\Attribute\AsTask; use Castor\Context; +use Symfony\Contracts\HttpClient\Exception\ExceptionInterface as HttpExceptionInterface; use Symfony\Component\Process\Exception\ExceptionInterface; use Symfony\Component\Process\ExecutableFinder; use Symfony\Component\Process\Process; @@ -15,6 +16,7 @@ use function Castor\context; use function Castor\finder; use function Castor\fs; +use function Castor\http_client; use function Castor\io; use function Castor\log; use function Castor\run; @@ -32,9 +34,11 @@ function about(): void io()->section('Available URLs for this project:'); $urls = [variable('root_domain'), ...variable('extra_domains')]; - $payload = @file_get_contents(sprintf('http://%s:8080/api/http/routers', variable('root_domain'))); - if ($payload) { - $routers = json_decode($payload, true); + try { + $routers = http_client() + ->request('GET', 'http://127.0.0.1:8080/api/http/routers') + ->toArray() + ; $projectName = variable('project_name'); foreach ($routers as $router) { if (!preg_match("{^{$projectName}-(.*)@docker$}", $router['name'])) { @@ -49,7 +53,9 @@ function about(): void $hosts = explode('`) || Host(`', $matches['hosts']); $urls = [...$urls, ...$hosts]; } + } catch (HttpExceptionInterface) { } + io()->listing(array_map(fn ($url) => "https://{$url}", $urls)); }