Skip to content

Commit

Permalink
Merge pull request #292 from jolicode/http-client
Browse files Browse the repository at this point in the history
use http_client() from castor
  • Loading branch information
pyrech committed Apr 5, 2024
2 parents 7c4afee + 62df1cd commit 5da05c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions .castor/docker.php
Expand Up @@ -7,6 +7,7 @@
use Castor\Attribute\AsTask;
use Castor\Context;
use Symfony\Component\Console\Input\InputOption;
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 @@ -16,6 +17,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\open;
Expand All @@ -34,9 +36,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', sprintf('http://%s:8080/api/http/routers', variable('root_domain')))
->toArray()
;
$projectName = variable('project_name');
foreach ($routers as $router) {
if (!preg_match("{^{$projectName}-(.*)@docker$}", $router['name'])) {
Expand All @@ -51,7 +55,9 @@ function about(): void
$hosts = explode('`) || Host(`', $matches['hosts']);
$urls = [...$urls, ...$hosts];
}
} catch (HttpExceptionInterface) {
}

io()->listing(array_map(fn ($url) => "https://{$url}", array_unique($urls)));
}

Expand Down
6 changes: 3 additions & 3 deletions castor.php
Expand Up @@ -12,10 +12,10 @@
use function docker\docker_compose_run;
use function docker\generate_certificates;
use function docker\up;
use function docker\workers_start;
use function docker\workers_stop;
// use function docker\workers_start;
// use function docker\workers_stop;

guard_min_version('0.14.0');
guard_min_version('0.15.0');

import(__DIR__ . '/.castor');

Expand Down

0 comments on commit 5da05c6

Please sign in to comment.