diff --git a/app/Http/Controllers/Api/Domains.php b/app/Http/Controllers/Api/Domains.php new file mode 100644 index 000000000..080f5aa4f --- /dev/null +++ b/app/Http/Controllers/Api/Domains.php @@ -0,0 +1,55 @@ +json(['error' => 'Invalid token.', 'docs' => 'https://coolify.io/docs/api/authentication'], 400); + } + $projects = ModelsProject::where('team_id', $teamId)->get(); + $domains = collect(); + $applications = $projects->pluck('applications')->flatten(); + if ($applications->count() > 0) { + foreach ($applications as $application) { + $ip = $application->destination->server->ip; + $fqdn = str($application->fqdn)->explode(',')->map(function ($fqdn) { + return str($fqdn)->replace('http://', '')->replace('https://', '')->replace('/', ''); + }); + $domains->push([ + 'domain' => $fqdn, + 'ip' => $ip, + ]); + } + } + $services = $projects->pluck('services')->flatten(); + if ($services->count() > 0) { + foreach ($services as $service) { + $service_applications = $service->applications; + if ($service_applications->count() > 0) { + foreach ($service_applications as $application) { + $fqdn = str($application->fqdn)->explode(',')->map(function ($fqdn) { + return str($fqdn)->replace('http://', '')->replace('https://', '')->replace('/', ''); + }); + $domains->push([ + 'domain' => $fqdn, + 'ip' => $ip, + ]); + } + } + } + } + $domains = $domains->groupBy('ip')->map(function ($domain) { + return $domain->pluck('domain')->flatten(); + }); + + return response()->json($domains); + } +} diff --git a/app/Models/Project.php b/app/Models/Project.php index b9afc7426..6416971f6 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -45,6 +45,10 @@ public function team() return $this->belongsTo(Team::class); } + public function services() + { + return $this->hasManyThrough(Service::class, Environment::class); + } public function applications() { return $this->hasManyThrough(Application::class, Environment::class); diff --git a/routes/api.php b/routes/api.php index 4ef5500f8..a1ddd666e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,6 +1,7 @@