From 5c3bd0f8147f7fdb8a037dbe4667a258385817ca Mon Sep 17 00:00:00 2001 From: Savio Resende Date: Wed, 2 Oct 2024 15:26:56 -0500 Subject: [PATCH] Adjustments for public assets. --- config/jacked-server.php | 13 +++++++------ src/Data/OpenSwooleConfig.php | 4 ++-- src/Services/Server.php | 15 +++++++++++++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/config/jacked-server.php b/config/jacked-server.php index 4d1dd82..465ba13 100644 --- a/config/jacked-server.php +++ b/config/jacked-server.php @@ -37,10 +37,11 @@ 'openswoole-server-settings' => [ // @phpstan-ignore-next-line 'document_root' => $_ENV['JACKED_SERVER_DOCUMENT_ROOT'] ?? ROOT_DIR, - 'enable_static_handler' => $_ENV['JACKED_SERVER_STATIC_ENABLED'] ?? true, + 'enable_static_handler' => ($_ENV['JACKED_SERVER_STATIC_ENABLED'] ?? 'true') === 'true', + 'enable_static_handler_locations' => ($_ENV['JACKED_SERVER_STATIC_LOCATIONS_ENABLED'] ?? 'false') === 'true', 'static_handler_locations' => explode( ',', - $_ENV['JACKED_SERVER_STATIC_LOCATIONS'] ?? '/imgs,/css,/js,/build', + $_ENV['JACKED_SERVER_STATIC_LOCATIONS'] ?? '/imgs,/css,/js,/build,/vendor', ), // reactor and workers @@ -64,7 +65,7 @@ // ------------------------------------------------------------ 'audit' => [ - 'enabled' => $_ENV['JACKED_SERVER_AUDIT_ENABLED'] ?? false, + 'enabled' => ($_ENV['JACKED_SERVER_AUDIT_ENABLED'] ?? 'false') === 'true', ], // ------------------------------------------------------------ @@ -99,15 +100,15 @@ // ------------------------------------------------------------ 'websocket' => [ - 'enabled' => $_ENV['JACKED_SERVER_WEBSOCKET_ENABLED'] ?? false, + 'enabled' => ($_ENV['JACKED_SERVER_WEBSOCKET_ENABLED'] ?? 'false') === 'true', // auth - 'auth' => $_ENV['JACKED_SERVER_WEBSOCKET_AUTH'] ?? false, + 'auth' => ($_ENV['JACKED_SERVER_WEBSOCKET_AUTH'] ?? 'false') === 'true', 'secret' => $_ENV['JACKED_SERVER_WEBSOCKET_SECRET'] ?? null, 'token' => $_ENV['JACKED_SERVER_WEBSOCKET_TOKEN'] ?? null, // features - 'acknowledgment' => $_ENV['JACKED_SERVER_WEBSOCKET_USE_ACKNOWLEDGMENT'] ?? false, + 'acknowledgment' => ($_ENV['JACKED_SERVER_WEBSOCKET_USE_ACKNOWLEDGMENT'] ?? 'false') === 'true', ], // ------------------------------------------------------------ diff --git a/src/Data/OpenSwooleConfig.php b/src/Data/OpenSwooleConfig.php index 30ef5b7..aecb13d 100644 --- a/src/Data/OpenSwooleConfig.php +++ b/src/Data/OpenSwooleConfig.php @@ -13,7 +13,6 @@ public function __construct( public string $documentRoot, public bool $enableStaticHandler, - public array $staticHandlerLocations, public int $reactorNum, public int $workerNum, public int $maxRequestExecutionTime, @@ -21,6 +20,7 @@ public function __construct( public ?string $sslKeyFile, public bool $openHttpProtocol, // public string $pidFile, + public array $staticHandlerLocations = [], ) { } @@ -32,7 +32,7 @@ public static function rules(): array return [ 'documentRoot' => ['required', 'string'], 'enableStaticHandler' => ['required', 'boolean'], - 'staticHandlerLocations' => ['required', 'array'], + 'staticHandlerLocations' => ['array'], 'reactorNum' => ['required', 'integer'], 'workerNum' => ['required', 'integer'], 'maxRequestExecutionTime' => ['required', 'integer'], diff --git a/src/Services/Server.php b/src/Services/Server.php index 15d010c..609e571 100644 --- a/src/Services/Server.php +++ b/src/Services/Server.php @@ -464,7 +464,7 @@ private function getServerConfig(): OpenSwooleConfig { $camelCasedSettings = []; foreach ( - array_merge(Config::get('openswoole-server-settings', [ + array_merge(Config::get('openswoole-server-settings', []), [ // base settings 'document_root' => $this->publicDocumentRoot, // @phpstan-ignore-line 'enable_static_handler' => true, @@ -476,12 +476,23 @@ private function getServerConfig(): OpenSwooleConfig // timeout 'max_request_execution_time' => $this->timeout, - ]), ($this->ssl ? [ + ], ($this->ssl ? [ 'ssl_cert_file' => $this->sslCertFile, 'ssl_key_file' => $this->sslKeyFile, 'open_http_protocol' => true, ] : [])) as $key => $value ) { + if ( + !Config::get('openswoole-server-settings.enable_static_handler_locations') + && $key === 'static_handler_locations' + ) { + continue; + } + + if ($key === 'enable_static_handler_locations') { + continue; + } + $camelCasedSettings[Str::camel($key)] = $value; }