diff --git a/changes/feat-backend-url-suggestion.md b/changes/feat-backend-url-suggestion.md index 4199d8de..e0ff62a9 100644 --- a/changes/feat-backend-url-suggestion.md +++ b/changes/feat-backend-url-suggestion.md @@ -1,3 +1,3 @@ Added -- The backend address field suggests honk's native API (`http://:9527`) when no backend is saved yet. +- On a page served over http, the backend address field suggests honk's native API (`http://:9527`) when no backend is saved yet. diff --git a/src/api/profiles.test.ts b/src/api/profiles.test.ts index 173684dd..ff6304f8 100644 --- a/src/api/profiles.test.ts +++ b/src/api/profiles.test.ts @@ -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(''); diff --git a/src/api/profiles.ts b/src/api/profiles.ts index d9a6c626..87ecb3b4 100644 --- a/src/api/profiles.ts +++ b/src/api/profiles.ts @@ -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`; } diff --git a/src/features/settings/Settings.tsx b/src/features/settings/Settings.tsx index 64571163..f09d3c79 100644 --- a/src/features/settings/Settings.tsx +++ b/src/features/settings/Settings.tsx @@ -351,7 +351,7 @@ export function Settings({query}: PageProps) { return (
- {firstRun &&

{t('settings.firstRun')}

} + {firstRun &&

{firstRun}

} {paired &&

{t('settings.paired')}

}