Skip to content

Commit

Permalink
use http_client() from castor
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx committed Mar 15, 2024
1 parent f77b13d commit 7cc8c02
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions .castor/docker.php
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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'])) {
Expand All @@ -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));
}

Expand Down

0 comments on commit 7cc8c02

Please sign in to comment.