Skip to content

Commit 480ae3d

Browse files
committed
Refactor Server.php to improve default 404 redirect setup
1 parent 21a5b4c commit 480ae3d

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

app/Models/Server.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,13 @@ public function setupDefault404Redirect()
165165
$dynamic_conf_path = $this->proxyPath().'/dynamic';
166166
$proxy_type = $this->proxyType();
167167
$redirect_url = $this->proxy->redirect_url;
168-
ray($proxy_type);
169168
if ($proxy_type === ProxyTypes::TRAEFIK->value) {
170169
$default_redirect_file = "$dynamic_conf_path/default_redirect_404.yaml";
171-
} elseif ($proxy_type === 'CADDY') {
170+
} elseif ($proxy_type === ProxyTypes::CADDY->value) {
172171
$default_redirect_file = "$dynamic_conf_path/default_redirect_404.caddy";
173172
}
174173
if (empty($redirect_url)) {
175-
if ($proxy_type === 'CADDY') {
174+
if ($proxy_type === ProxyTypes::CADDY->value) {
176175
$conf = ':80, :443 {
177176
respond 404
178177
}';
@@ -242,7 +241,7 @@ public function setupDefault404Redirect()
242241
$conf;
243242

244243
$base64 = base64_encode($conf);
245-
} elseif ($proxy_type === 'CADDY') {
244+
} elseif ($proxy_type === ProxyTypes::CADDY->value) {
246245
$conf = ":80, :443 {
247246
redir $redirect_url
248247
}";
@@ -258,9 +257,6 @@ public function setupDefault404Redirect()
258257
"echo '$base64' | base64 -d | tee $default_redirect_file > /dev/null",
259258
], $this);
260259

261-
if (config('app.env') == 'local') {
262-
ray($conf);
263-
}
264260
if ($proxy_type === 'CADDY') {
265261
$this->reloadCaddy();
266262
}
@@ -908,7 +904,7 @@ public function ip(): Attribute
908904
{
909905
return Attribute::make(
910906
get: function ($value) {
911-
return preg_replace('/[^0-9a-zA-Z.-]/', '', $value);
907+
return preg_replace('/[^0-9a-zA-Z.:%-]/', '', $value);
912908
}
913909
);
914910
}

0 commit comments

Comments
 (0)