Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/components/DomainFormModal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { describe, it, expect, afterEach } from "vitest";
import { mount, type VueWrapper } from "@vue/test-utils";
import DomainFormModal from "./DomainFormModal.vue";
import type { DomainConfig } from "@/types";

let wrapper: VueWrapper;

const mountModal = (domain?: DomainConfig) => {
wrapper = mount(DomainFormModal, {
attachTo: document.body,
props: {
visible: true,
domain: domain ?? null,
services: [],
deploymentName: "shop",
},
});
return wrapper;
};

afterEach(() => {
wrapper?.unmount();
document.body.innerHTML = "";
});

describe("DomainFormModal routing-only hostnames", () => {
it("hydrates existing routing-only hostnames into their own inputs", () => {
mountModal({
id: "d1",
service: "web",
container_port: 80,
domain: "api.example.com",
ssl: { enabled: true, auto_cert: true },
route_only_aliases: ["dashboard.example.com"],
});

const inputs = Array.from(document.querySelectorAll<HTMLInputElement>("input")).map((i) => i.value);
expect(inputs).toContain("dashboard.example.com");
});

it("emits routing-only hostnames separately from certificate-bearing aliases", async () => {
const wrapper = mountModal({
id: "d1",
service: "web",
container_port: 80,
domain: "api.example.com",
ssl: { enabled: true, auto_cert: true },
aliases: ["www.example.com"],
route_only_aliases: ["dashboard.example.com"],
});

document.querySelector<HTMLButtonElement>(".btn-primary")?.click();
await wrapper.vm.$nextTick();

const saved = wrapper.emitted("save")?.[0]?.[0] as DomainConfig;
expect(saved.aliases).toEqual(["www.example.com"]);
expect(saved.route_only_aliases).toEqual(["dashboard.example.com"]);
});
});
38 changes: 38 additions & 0 deletions src/components/DomainFormModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,31 @@
</div>
<span class="hint">Additional domain names that should also resolve here</span>
</div>

<div class="form-group">
<label>Routing-only hostnames</label>
<div class="aliases-input">
<div v-for="(alias, index) in form.route_only_aliases" :key="index" class="alias-item">
<input
v-model="form.route_only_aliases[index]"
type="text"
class="form-input"
placeholder="dashboard.example.com"
/>
<button type="button" class="remove-btn" @click="removeRouteOnly(index)">

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The remove button lacks an accessible label. Since it only contains an icon, screen readers won't be able to describe the action to users.

Suggested change
<button type="button" class="remove-btn" @click="removeRouteOnly(index)">
<button type="button" class="remove-btn" @click="removeRouteOnly(index)" aria-label="Remove hostname">
<i class="pi pi-times" />
</button>

<i class="pi pi-times" />
</button>
</div>
<button type="button" class="btn btn-sm btn-secondary" @click="addRouteOnly">
<i class="pi pi-plus" />
Add hostname
</button>
</div>
<span class="hint">
Routed here but never issued a certificate, for a hostname whose TLS is terminated by an external proxy
(e.g. Cloudflare). It shares this domain's certificate over the proxy's SNI.
</span>
</div>
</form>

<div class="modal-footer">
Expand Down Expand Up @@ -129,6 +154,7 @@ const form = ref<{
strip_prefix: boolean;
ssl: { enabled: boolean; auto_cert: boolean };
aliases: string[];
route_only_aliases: string[];
}>({
domain: "",
service: "",
Expand All @@ -137,6 +163,7 @@ const form = ref<{
strip_prefix: false,
ssl: { enabled: false, auto_cert: false },
aliases: [],
route_only_aliases: [],
});

watch(
Expand All @@ -155,6 +182,7 @@ watch(
auto_cert: props.domain.ssl?.auto_cert || false,
},
aliases: [...(props.domain.aliases || [])],
route_only_aliases: [...(props.domain.route_only_aliases || [])],
};
} else {
form.value = {
Expand All @@ -165,6 +193,7 @@ watch(
strip_prefix: false,
ssl: { enabled: false, auto_cert: false },
aliases: [],
route_only_aliases: [],
};
}
}
Expand All @@ -184,6 +213,14 @@ function removeAlias(index: number) {
form.value.aliases.splice(index, 1);
}

function addRouteOnly() {
form.value.route_only_aliases.push("");
}

function removeRouteOnly(index: number) {
form.value.route_only_aliases.splice(index, 1);
}

function handleSubmit() {
if (!isValid.value) return;

Expand All @@ -196,6 +233,7 @@ function handleSubmit() {
strip_prefix: form.value.strip_prefix || undefined,
ssl: form.value.ssl,
aliases: form.value.aliases.filter((a) => a.trim() !== ""),
route_only_aliases: form.value.route_only_aliases.filter((a) => a.trim() !== ""),
};

emit("save", domainData);
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface DomainConfig {
strip_prefix?: boolean;
ssl: SSLConfig;
aliases?: string[];
route_only_aliases?: string[];
}

export interface QuickAction {
Expand Down
Loading