An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
Refactor: Centralize service application prerequisites
Andras Bacsai4706bc23aa86
diff --git a/app/Http/Controllers/Api/ApplicationsController.php b/app/Http/Controllers/Api/ApplicationsController.phpindex 6b4f1efeeb..ea3998f8ac 100644--- a/app/Http/Controllers/Api/ApplicationsController.php+++ b/app/Http/Controllers/Api/ApplicationsController.php@@ -1652,6 +1652,10 @@ class ApplicationsController extends Controller$service->save();$service->parse(isNew: true);++ // Apply service-specific application prerequisites+ applyServiceApplicationPrerequisites($service);+if ($instantDeploy) {StartService::dispatch($service);}diff --git a/app/Http/Controllers/Api/ServicesController.php b/app/Http/Controllers/Api/ServicesController.phpindex 7440cc16a0..587f49fa5a 100644--- a/app/Http/Controllers/Api/ServicesController.php+++ b/app/Http/Controllers/Api/ServicesController.php@@ -376,6 +376,10 @@ class ServicesController extends Controller});}$service->parse(isNew: true);++ // Apply service-specific application prerequisites+ applyServiceApplicationPrerequisites($service);+if ($instantDeploy) {StartService::dispatch($service);}diff --git a/app/Livewire/Project/New/DockerCompose.php b/app/Livewire/Project/New/DockerCompose.phpindex a88a62d88e..18bb237afd 100644--- a/app/Livewire/Project/New/DockerCompose.php+++ b/app/Livewire/Project/New/DockerCompose.php@@ -74,6 +74,9 @@ class DockerCompose extends Component}$service->parse(isNew: true);+ // Apply service-specific application prerequisites+ applyServiceApplicationPrerequisites($service);+return redirect()->route('project.service.configuration', ['service_uuid' => $service->uuid,'environment_uuid' => $environment->uuid,diff --git a/app/Livewire/Project/Resource/Create.php b/app/Livewire/Project/Resource/Create.phpindex f4c5f81b0f..5bae8d5f07 100644--- a/app/Livewire/Project/Resource/Create.php+++ b/app/Livewire/Project/Resource/Create.php@@ -104,25 +104,8 @@ class Create extends Component}$service->parse(isNew: true);- // For Beszel service disable gzip (fixes realtime not working issue)- if ($oneClickServiceName === 'beszel') {- $appService = $service->applications()->whereName('beszel')->first();- if ($appService) {- $appService->is_gzip_enabled = false;- $appService->save();- }- }- // For Appwrite services, disable strip prefix for services that handle domain requests- if ($oneClickServiceName === 'appwrite') {- $servicesToDisableStripPrefix = ['appwrite', 'appwrite-console', 'appwrite-realtime'];- foreach ($servicesToDisableStripPrefix as $serviceName) {- $appService = $service->applications()->whereName($serviceName)->first();- if ($appService) {- $appService->is_stripprefix_enabled = false;- $appService->save();- }- }- }+ // Apply service-specific application prerequisites+ applyServiceApplicationPrerequisites($service);return redirect()->route('project.service.configuration', ['service_uuid' => $service->uuid,diff --git a/bootstrap/helpers/constants.php b/bootstrap/helpers/constants.phpindex 6d9136b027..178876b89a 100644--- a/bootstrap/helpers/constants.php+++ b/bootstrap/helpers/constants.php@@ -71,4 +71,10 @@ const NEEDS_TO_CONNECT_TO_PREDEFINED_NETWORK = ['pgadmin','postgresus',];+const NEEDS_TO_DISABLE_GZIP = [+ 'beszel' => ['beszel'],+];+const NEEDS_TO_DISABLE_STRIPPREFIX = [+ 'appwrite' => ['appwrite', 'appwrite-console', 'appwrite-realtime'],+];const SHARED_VARIABLE_TYPES = ['team', 'project', 'environment'];diff --git a/bootstrap/helpers/services.php b/bootstrap/helpers/services.phpindex 3fff2c090f..7e63f12d60 100644--- a/bootstrap/helpers/services.php+++ b/bootstrap/helpers/services.php@@ -339,3 +339,55 @@ function parseServiceEnvironmentVariable(string $key): array'has_port' => $hasPort,];}++/**+ * Apply service-specific application prerequisites after service parse.+ *+ * This function configures application-level settings that are required for+ * specific one-click services to work correctly (e.g., disabling gzip for Beszel,+ * disabling strip prefix for Appwrite services).+ *+ * Must be called AFTER $service->parse() since it requires applications to exist.+ *+ * @param Service $service The service to apply prerequisites to+ * @return void+ */+function applyServiceApplicationPrerequisites(Service $service): void+{+ try {+ // Extract service name from service name (format: "servicename-uuid")+ $serviceName = str($service->name)->before('-')->value();++ // Apply gzip disabling if needed+ if (array_key_exists($serviceName, NEEDS_TO_DISABLE_GZIP)) {+ $applicationNames = NEEDS_TO_DISABLE_GZIP[$serviceName];+ foreach ($applicationNames as $applicationName) {+ $application = $service->applications()->whereName($applicationName)->first();+ if ($application) {+ $application->is_gzip_enabled = false;+ $application->save();+ }+ }+ }++ // Apply stripprefix disabling if needed+ if (array_key_exists($serviceName, NEEDS_TO_DISABLE_STRIPPREFIX)) {+ $applicationNames = NEEDS_TO_DISABLE_STRIPPREFIX[$serviceName];+ foreach ($applicationNames as $applicationName) {+ $application = $service->applications()->whereName($applicationName)->first();+ if ($application) {+ $application->is_stripprefix_enabled = false;+ $application->save();+ }+ }+ }+ } catch (\Throwable $e) {+ // Log error but don't throw - prerequisites are nice-to-have, not critical+ Log::error('Failed to apply service application prerequisites', [+ 'service_id' => $service->id,+ 'service_name' => $service->name,+ 'error' => $e->getMessage(),+ 'trace' => $e->getTraceAsString(),+ ]);+ }+}diff --git a/tests/Unit/ServiceApplicationPrerequisitesTest.php b/tests/Unit/ServiceApplicationPrerequisitesTest.phpnew file mode 100644index 0000000000..afe2e1dcdc--- /dev/null+++ b/tests/Unit/ServiceApplicationPrerequisitesTest.php@@ -0,0 +1,103 @@+<?php++use App\Models\Service;+use App\Models\ServiceApplication;+use Illuminate\Database\Eloquent\Collection;++it('applies beszel gzip prerequisite correctly', function () {+ $application = Mockery::mock(ServiceApplication::class);+ $application->shouldReceive('save')->once();+ $application->is_gzip_enabled = true; // Start as enabled++ $query = Mockery::mock();+ $query->shouldReceive('whereName')+ ->with('beszel')+ ->once()+ ->andReturnSelf();+ $query->shouldReceive('first')+ ->once()+ ->andReturn($application);++ $service = Mockery::mock(Service::class);+ $service->name = 'beszel-test-uuid';+ $service->id = 1;+ $service->shouldReceive('applications')+ ->once()+ ->andReturn($query);++ applyServiceApplicationPrerequisites($service);++ expect($application->is_gzip_enabled)->toBeFalse();+});++it('applies appwrite stripprefix prerequisite correctly', function () {+ $applications = [];++ foreach (['appwrite', 'appwrite-console', 'appwrite-realtime'] as $name) {+ $app = Mockery::mock(ServiceApplication::class);+ $app->is_stripprefix_enabled = true; // Start as enabled+ $app->shouldReceive('save')->once();+ $applications[$name] = $app;+ }++ $service = Mockery::mock(Service::class);+ $service->name = 'appwrite-test-uuid';+ $service->id = 1;++ $service->shouldReceive('applications')->times(3)->andReturnUsing(function () use (&$applications) {+ static $callCount = 0;+ $names = ['appwrite', 'appwrite-console', 'appwrite-realtime'];+ $currentName = $names[$callCount++];++ $query = Mockery::mock();+ $query->shouldReceive('whereName')+ ->with($currentName)+ ->once()+ ->andReturnSelf();+ $query->shouldReceive('first')+ ->once()+ ->andReturn($applications[$currentName]);++ return $query;+ });++ applyServiceApplicationPrerequisites($service);++ foreach ($applications as $app) {+ expect($app->is_stripprefix_enabled)->toBeFalse();+ }+});++it('handles missing applications gracefully', function () {+ $query = Mockery::mock();+ $query->shouldReceive('whereName')+ ->with('beszel')+ ->once()+ ->andReturnSelf();+ $query->shouldReceive('first')+ ->once()+ ->andReturn(null);++ $service = Mockery::mock(Service::class);+ $service->name = 'beszel-test-uuid';+ $service->id = 1;+ $service->shouldReceive('applications')+ ->once()+ ->andReturn($query);++ // Should not throw exception+ applyServiceApplicationPrerequisites($service);++ expect(true)->toBeTrue();+});++it('skips services without prerequisites', function () {+ $service = Mockery::mock(Service::class);+ $service->name = 'unknown-service-uuid';+ $service->id = 1;+ $service->shouldNotReceive('applications');++ applyServiceApplicationPrerequisites($service);++ expect(true)->toBeTrue();+});