fix(previews): avoid doubled scheme in preview URL templates

Closes #12136

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Andras Bacsai
2026-10-11 09:51:41 +02:00
co-authored by Claude Opus 5.5
parent f55efc859d
commit d4502bc514
2 changed files with 16 additions and 0 deletions
+4
View File
@@ -337,6 +337,10 @@ class ApplicationPreview extends BaseModel
$previewFqdn = str_replace('{{random}}', $random, $template);
$previewFqdn = str_replace('{{domain}}', $host, $previewFqdn);
$previewFqdn = str_replace('{{pr_id}}', (string) $this->pull_request_id, $previewFqdn);
if (preg_match('#^(https?)://(.*)$#i', $previewFqdn, $matches)) {
$schema = strtolower($matches[1]);
$previewFqdn = $matches[2];
}
$previewUrl = "{$schema}://{$previewFqdn}{$path}";
$sourceCanonical = DomainPortOverrides::withoutPort($sourceDomain);
$port = $url->getPort() ?? ($this->application->domain_port_overrides[$sourceCanonical] ?? null);
@@ -394,6 +394,18 @@ it('copies the parent domain port override onto a generated preview domain', fun
->toBe([8080]);
});
it('uses the preview url template scheme instead of the parent scheme', function (string $template, string $expected) {
$this->application->update(['preview_url_template' => $template]);
$preview = createPreviewForPortTests($this->application, 2163);
expect($preview->generatedPreviewDomain('http://app.example.com/api')['url'])->toBe($expected);
})->with([
'explicit https' => ['https://{{pr_id}}.preview.example.com', 'https://2163.preview.example.com/api'],
'explicit uppercase https' => ['HTTPS://{{pr_id}}.preview.example.com', 'https://2163.preview.example.com/api'],
'scheme-less inherits parent' => ['{{pr_id}}.preview.example.com', 'http://2163.preview.example.com/api'],
]);
it('keeps every generated preview domain port override in the legacy compose parser', function () {
$this->application->update([
'build_pack' => 'dockercompose',