diff --git a/site/src/locales/en.json b/site/src/locales/en.json index 1a50001..43d1de1 100644 --- a/site/src/locales/en.json +++ b/site/src/locales/en.json @@ -281,6 +281,7 @@ "customDomainsLabel": "Custom Domains", "customDomainsPlaceholder": "example.com, www.example.com", "customDomainsDesc": "Multiple domains separated by commas", + "addCustomDomain": "Add Domain", "subdomain": "Subdomain", "subdomainPlaceholder": "myapp", "subdomainDesc": "Subdomain for the proxy", diff --git a/site/src/locales/zh.json b/site/src/locales/zh.json index 09ef85a..f539fb9 100644 --- a/site/src/locales/zh.json +++ b/site/src/locales/zh.json @@ -281,6 +281,7 @@ "customDomainsLabel": "自定义域名", "customDomainsPlaceholder": "example.com, www.example.com", "customDomainsDesc": "多个域名用逗号分隔", + "addCustomDomain": "添加域名", "subdomain": "子域名", "subdomainPlaceholder": "myapp", "subdomainDesc": "代理的子域名", diff --git a/site/src/pages/Proxies/ProxyFormPage/ProxyFormPage.view.tsx b/site/src/pages/Proxies/ProxyFormPage/ProxyFormPage.view.tsx index 2897a49..9b716da 100644 --- a/site/src/pages/Proxies/ProxyFormPage/ProxyFormPage.view.tsx +++ b/site/src/pages/Proxies/ProxyFormPage/ProxyFormPage.view.tsx @@ -58,7 +58,7 @@ interface ProxyFormPageViewProps { isHttpType: boolean; isSocks5Plugin: boolean; mounted: boolean; - onChange: (field: keyof ProxyFormData, value: string | boolean) => void; + onChange: (field: keyof ProxyFormData, value: string | boolean | string[]) => void; onSubmit: () => void; onCancel: () => void; onNavigateToServers: () => void; @@ -240,15 +240,44 @@ export function ProxyFormPageView({ {isHttpType ? ( <> - onChange("customDomains", e.target.value)} - /> - - {t("proxy.customDomainsDesc")} - + + {formData.customDomains.map((domain, index) => ( + + { + const next = [...formData.customDomains]; + next[index] = e.target.value; + onChange("customDomains", next); + }} + /> + + + ))} + + { try { setLoadingServers(true); - const records = await pb.collection("fh_servers").getFullList({ - sort: "-created", - fields: "id,serverName,bootStatus,networkStatus", - }); - const list = records.map((r) => ({ - id: r.id, - serverName: r.serverName as string, - bootStatus: (r.bootStatus as string) || "stopped", - networkStatus: r.networkStatus as ServerOption["networkStatus"], - })); + const res = await apiGet("/api/servers/options"); + if (!res.ok) throw new Error("Failed to fetch servers"); + const list: ServerOption[] = await res.json(); setServers(list); if (list.length > 0 && !isEditing) { setFormData((prev) => ({ ...prev, serverId: list[0].id })); @@ -107,7 +101,7 @@ export function useProxyForm() { localPort: String(record.localPort || ""), remotePort: String(record.remotePort || ""), subdomain: (record.subdomain as string) || "", - customDomains: (record.customDomains as string[] | undefined)?.join(", ") || "", + customDomains: (record.customDomains as string[] | undefined) || [], encryption: (record.transport as Record | undefined)?.use_encryption || false, compression: (record.transport as Record | undefined)?.use_compression || false, description: (record.description as string) || "", @@ -145,7 +139,7 @@ export function useProxyForm() { setErrors((prev) => ({ ...prev, [field]: error })); }; - const handleChange = (field: keyof ProxyFormData, value: string | boolean) => { + const handleChange = (field: keyof ProxyFormData, value: string | boolean | string[]) => { setFormData((prev) => { const next = { ...prev, [field]: value }; if (field === "type" && value !== "tcp" && prev.pluginEnabled && prev.pluginType === "socks5") { @@ -154,6 +148,9 @@ export function useProxyForm() { return next; }); if (typeof value === "string") validateField(field, value); + if (Array.isArray(value) && field === "customDomains") { + setErrors((prev) => ({ ...prev, customDomains: undefined })); + } }; const validate = (data: ProxyFormData): boolean => { @@ -178,7 +175,7 @@ export function useProxyForm() { else if (!REGEX.PORT.test(data.remotePort)) newErrors.remotePort = t("proxy.errorInvalidPort"); } - if (isHttp && !data.subdomain && !data.customDomains) { + if (isHttp && !data.subdomain && data.customDomains.length === 0) { newErrors.subdomain = t("proxy.errorSubdomainRequired"); } @@ -205,9 +202,7 @@ export function useProxyForm() { localPort: formData.localPort, remotePort: formData.remotePort, subdomain: formData.subdomain, - customDomains: formData.customDomains - ? formData.customDomains.split(",").map((d) => d.trim()).filter(Boolean) - : [], + customDomains: formData.customDomains, transport: { use_encryption: formData.encryption, use_compression: formData.compression,