Skip to content

Commit

Permalink
Adjustments for public assets.
Browse files Browse the repository at this point in the history
  • Loading branch information
lotharthesavior committed Oct 2, 2024
1 parent 292f1ca commit 5c3bd0f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
13 changes: 7 additions & 6 deletions config/jacked-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -64,7 +65,7 @@
// ------------------------------------------------------------

'audit' => [
'enabled' => $_ENV['JACKED_SERVER_AUDIT_ENABLED'] ?? false,
'enabled' => ($_ENV['JACKED_SERVER_AUDIT_ENABLED'] ?? 'false') === 'true',
],

// ------------------------------------------------------------
Expand Down Expand Up @@ -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',
],

// ------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/Data/OpenSwooleConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
public function __construct(
public string $documentRoot,
public bool $enableStaticHandler,
public array $staticHandlerLocations,
public int $reactorNum,
public int $workerNum,
public int $maxRequestExecutionTime,
public ?string $sslCertFile,
public ?string $sslKeyFile,
public bool $openHttpProtocol,
// public string $pidFile,
public array $staticHandlerLocations = [],
) {
}

Expand All @@ -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'],
Expand Down
15 changes: 13 additions & 2 deletions src/Services/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

Expand Down

0 comments on commit 5c3bd0f

Please sign in to comment.