refactor: improve proxy configuration and code consistency in Server model
- Standardized spacing in conditional statements for better readability. - Updated proxy redirect handling to ensure default values are set correctly. - Modified dynamic configuration path concatenation for clarity. - Changed router rule to 'PathPrefix' and adjusted priority for better routing behavior. - Replaced empty check with 'filled' helper for improved code clarity.
This commit is contained in:
parent
f82d95e908
commit
659309c5b4
1 changed files with 9 additions and 10 deletions
|
|
@ -105,12 +105,12 @@ protected static function booted()
|
|||
]);
|
||||
}
|
||||
}
|
||||
if (!isset($server->proxy->redirect_enabled)) {
|
||||
if (! isset($server->proxy->redirect_enabled)) {
|
||||
$server->proxy->redirect_enabled = true;
|
||||
}
|
||||
});
|
||||
static::retrieved(function ($server) {
|
||||
if (!isset($server->proxy->redirect_enabled)) {
|
||||
if (! isset($server->proxy->redirect_enabled)) {
|
||||
$server->proxy->redirect_enabled = true;
|
||||
}
|
||||
});
|
||||
|
|
@ -197,7 +197,7 @@ public function setupDefaultRedirect()
|
|||
$banner =
|
||||
"# This file is generated by Coolify, do not edit it manually.\n".
|
||||
"# Disable the default redirect to customize (only if you know what are you doing).\n\n";
|
||||
$dynamic_conf_path = $this->proxyPath() . '/dynamic';
|
||||
$dynamic_conf_path = $this->proxyPath().'/dynamic';
|
||||
$proxy_type = $this->proxyType();
|
||||
$redirect_enabled = $this->proxy->redirect_enabled ?? true;
|
||||
$redirect_url = $this->proxy->redirect_url;
|
||||
|
|
@ -214,7 +214,7 @@ public function setupDefaultRedirect()
|
|||
"rm -f $dynamic_conf_path/default_redirect_404.caddy",
|
||||
], $this);
|
||||
|
||||
if (!$redirect_enabled) {
|
||||
if (! $redirect_enabled) {
|
||||
instant_remote_process(["rm -f $default_redirect_file"], $this);
|
||||
} else {
|
||||
if ($proxy_type === ProxyTypes::CADDY->value) {
|
||||
|
|
@ -237,11 +237,8 @@ public function setupDefaultRedirect()
|
|||
1 => 'https',
|
||||
],
|
||||
'service' => 'noop',
|
||||
'rule' => 'HostRegexp(`.+`)',
|
||||
'tls' => [
|
||||
'certResolver' => 'letsencrypt',
|
||||
],
|
||||
'priority' => 1,
|
||||
'rule' => 'PathPrefix(`/`)',
|
||||
'priority' => -1000,
|
||||
],
|
||||
],
|
||||
'services' => [
|
||||
|
|
@ -253,10 +250,11 @@ public function setupDefaultRedirect()
|
|||
],
|
||||
],
|
||||
];
|
||||
if (!empty($redirect_url)) {
|
||||
if (filled($redirect_url)) {
|
||||
$dynamic_conf['http']['routers']['catchall']['middlewares'] = [
|
||||
0 => 'redirect-regexp',
|
||||
];
|
||||
|
||||
$dynamic_conf['http']['services']['noop']['loadBalancer']['servers'][0] = [
|
||||
'url' => '',
|
||||
];
|
||||
|
|
@ -607,6 +605,7 @@ public function getMemoryMetrics(int $mins = 5)
|
|||
$memory = json_decode($memory, true);
|
||||
$parsedCollection = collect($memory)->map(function ($metric) {
|
||||
$usedPercent = $metric['usedPercent'] ?? 0.0;
|
||||
|
||||
return [(int) $metric['time'], (float) $usedPercent];
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue