'required|url', 'port' => 'required|numeric', 'is_static' => 'required|boolean', 'publish_directory' => 'nullable|string', ]; public function mount() { if (config('app.env') === 'local') { $this->public_repository_url = 'https://github.com/coollabsio/coolify-examples/tree/nodejs-fastify'; $this->port = 3000; } $this->parameters = getParameters(); $this->servers = session('currentTeam')->load(['servers'])->servers; } public function chooseServer($server) { $this->chosenServer = $server; $this->standalone_docker = StandaloneDocker::where('server_id', $server['id'])->get(); $this->swarm_docker = SwarmDocker::where('server_id', $server['id'])->get(); } public function setDestination($destination_uuid, $destination_type) { $class = "App\Models\\{$destination_type}"; $instance = new $class; $this->chosenDestination = $instance::where('uuid', $destination_uuid)->first(); } public function instantSave() { if ($this->is_static) { $this->port = 80; $this->publish_directory = '/dist'; } else { $this->port = 3000; $this->publish_directory = null; } $this->emit('saved', 'Application settings updated!'); } public function submit() { $this->validate(); $url = Url::fromString($this->public_repository_url); $git_host = $url->getHost(); $git_repository = $url->getSegment(1) . '/' . $url->getSegment(2); $git_branch = $url->getSegment(4) ?? 'main'; if ($this->type === 'project') { $project = Project::create([ 'name' => generateRandomName(), 'team_id' => session('currentTeam')->id, ]); $environment = $project->environments->first(); } else { $project = Project::where('uuid', $this->parameters['project_uuid'])->firstOrFail(); $environment = $project->environments->where('name', $this->parameters['environment_name'])->firstOrFail(); } $application_init = [ 'name' => generateRandomName(), 'git_repository' => $git_repository, 'git_branch' => $git_branch, 'build_pack' => 'nixpacks', 'ports_exposes' => $this->port, 'publish_directory' => $this->publish_directory, 'environment_id' => $environment->id, 'destination_id' => $this->chosenDestination->id, 'destination_type' => $this->chosenDestination->getMorphClass(), ]; if ($git_host == 'github.com') { $application_init['source_id'] = GithubApp::where('name', 'Public GitHub')->first()->id; $application_init['source_type'] = GithubApp::class; } elseif ($git_host == 'gitlab.com') { $application_init['source_id'] = GitlabApp::where('name', 'Public GitLab')->first()->id; $application_init['source_type'] = GitlabApp::class; } elseif ($git_host == 'bitbucket.org') { } $application = Application::create($application_init); $application->settings->is_static = $this->is_static; $application->settings->save(); return redirect()->route('project.application.configuration', [ 'project_uuid' => $project->uuid, 'environment_name' => $environment->name, 'application_uuid' => $application->uuid, ]); } }