wowowowowo
This commit is contained in:
38
app/Support/CaddyRouteRenderer.php
Normal file
38
app/Support/CaddyRouteRenderer.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Models\EnvironmentAttachment;
|
||||
|
||||
class CaddyRouteRenderer
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $upstreams
|
||||
*/
|
||||
public function render(EnvironmentAttachment $attachment, array $upstreams): string
|
||||
{
|
||||
$config = $attachment->serviceSlice?->config ?? [];
|
||||
$domain = $config['domain'] ?? $attachment->serviceSlice?->name ?? $attachment->environment->name;
|
||||
$pathPrefix = $config['path_prefix'] ?? '/';
|
||||
$siteAddress = ($config['tls_enabled'] ?? true) ? $domain : "http://{$domain}";
|
||||
$upstreamTargets = $upstreams === [] ? ['web:80'] : $upstreams;
|
||||
|
||||
if ($pathPrefix === '/') {
|
||||
return implode("\n", [
|
||||
"{$siteAddress} {",
|
||||
' reverse_proxy '.implode(' ', $upstreamTargets),
|
||||
'}',
|
||||
]);
|
||||
}
|
||||
|
||||
$normalizedPath = rtrim($pathPrefix, '/');
|
||||
|
||||
return implode("\n", [
|
||||
"{$siteAddress} {",
|
||||
" handle_path {$normalizedPath}* {",
|
||||
' reverse_proxy '.implode(' ', $upstreamTargets),
|
||||
' }',
|
||||
'}',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user