fix(settings): suggest the backend only on http pages

An https page cannot call honk's plain-http listener, so it gets no
suggestion. While the field holds an unsaved address, the first-run
note says the demo data stays until the URL is saved.
This commit is contained in:
Zakk committed 2026-10-20 04:53:35 +11:00
1 parent 8890314d4f
commit 20429992eb
8 files changed
+11 -7

No files matched your search

+1 -1
View File
@@ -1,3 +1,3 @@
Added
- The backend address field suggests honk's native API (`http://<this-host>:9527`) when no backend is saved yet.
- On a page served over http, the backend address field suggests honk's native API (`http://<this-host>:9527`) when no backend is saved yet.
+1 -1
View File
@@ -110,7 +110,7 @@ it('clears only the saved token of the profile signing out', async () => {
it('suggests honk on the page host when no backend is saved', () => {
expect(suggestedBackendUrl({protocol: 'http:', hostname: '192.168.1.1'})).toBe('http://192.168.1.1:9527');
expect(suggestedBackendUrl({protocol: 'https:', hostname: 'honk.example'})).toBe('http://honk.example:9527');
expect(suggestedBackendUrl({protocol: 'https:', hostname: 'honk.example'})).toBe('');
expect(suggestedBackendUrl({protocol: 'http:', hostname: '::1'})).toBe('http://[::1]:9527');
expect(suggestedBackendUrl({protocol: 'file:', hostname: ''})).toBe('');
expect(suggestedBackendUrl({protocol: 'http:', hostname: ''})).toBe('');
+3 -3
View File
@@ -145,10 +145,10 @@ export function hostedRoot(loc: {origin: string; pathname: string}): string {
}
// The backend address suggested when nothing is saved: honk's native API
// (port 9527) on this page's host. Empty when the page is not served over
// http(s), where no host applies.
// (port 9527) on this page's host. Empty unless the page is served over plain
// http: honk's listener speaks http, which an https page may not call.
export function suggestedBackendUrl(loc: {protocol: string; hostname: string} = location): string {
if (!/^https?:$/.test(loc.protocol) || !loc.hostname) return '';
if (loc.protocol !== 'http:' || !loc.hostname) return '';
const host = loc.hostname.includes(':') ? `[${loc.hostname}]` : loc.hostname;
return `http://${host}:9527`;
}
+1 -1
View File
@@ -351,7 +351,7 @@ export function Settings({query}: PageProps) {
return (
<div className="rp-page">
{firstRun && <p className="rp-note">{t('settings.firstRun')}</p>}
{firstRun && <p className="rp-note">{firstRun}</p>}
{paired && <p className="rp-note">{t('settings.paired')}</p>}
<Tabs
page
+2 -1
View File
@@ -36,7 +36,8 @@ export function useSettingsPage(query: string) {
profile,
error: capabilities.error,
retry: capabilities.refetch,
firstRun: form.saved.api === null,
// Until something is saved the app shows demo data, whatever address the field holds.
firstRun: form.saved.api === null ? t(form.demo ? 'settings.firstRun' : 'settings.firstRunUnsaved') : null,
activeId: form.saved.activeId,
hasActive: !!form.active,
profileReason: profileReason(!!form.active, t),
+1
View File
@@ -1735,6 +1735,7 @@
"settings.demo": "Using built-in demo data; no external backend was contacted.",
"settings.dnsLogSize": "DNS log records kept",
"settings.firstRun": "No backend configured; showing built-in demo data",
"settings.firstRunUnsaved": "No backend configured; showing built-in demo data until the backend URL is saved",
"settings.flowsMax": "Flows kept",
"settings.flowsRetention": "Flow retention (seconds)",
"settings.general": "General",
+1
View File
@@ -1534,6 +1534,7 @@
"settings.demo": "当前使用内置演示数据,未连接外部后端。",
"settings.dnsLogSize": "DNS 记录保留条数",
"settings.firstRun": "尚未设置后端;当前显示的是内置演示数据",
"settings.firstRunUnsaved": "尚未设置后端;保存后端网址前显示内置演示数据",
"settings.flowsMax": "流程保留条数",
"settings.flowsRetention": "流程保留秒数",
"settings.general": "通用",
+1
View File
@@ -1534,6 +1534,7 @@
"settings.demo": "目前使用內建示範資料,未連線至外部後端。",
"settings.dnsLogSize": "DNS 記錄保留筆數",
"settings.firstRun": "尚未設定後端;現在顯示的是內建示範資料",
"settings.firstRunUnsaved": "尚未設定後端;儲存後端網址前顯示內建示範資料",
"settings.flowsMax": "流程保留筆數",
"settings.flowsRetention": "流程保留秒數",
"settings.general": "一般",