Skip to content

The agent that grows with you

fix(webapp-access): a Webapp served only on this computer shows as local in Web Access

emozilla85e04c295b6b
diff --git a/apps/desktop/src/api/webapp-access.ts b/apps/desktop/src/api/webapp-access.ts
index 38d6609eeb4..39270f76cba 100644
--- a/apps/desktop/src/api/webapp-access.ts
+++ b/apps/desktop/src/api/webapp-access.ts
@@ -11,7 +11,8 @@ export interface WebAccessStatus {
/** What the gateway serves now; `stopped` when none answers. */
gateway: { reason: null | string; state: 'off' | 'serving' | 'stopped' | 'unavailable'; url: null | string }
lan_address: null | string
- mode: null | WebAccessMode
+ /** Who the configured web app serves; `local` is a loopback bind, reachable from this computer only. */
+ mode: 'local' | null | WebAccessMode
nous_signed_in: boolean
port: number
public_url: string
diff --git a/apps/desktop/src/app/settings/web-access-settings.test.tsx b/apps/desktop/src/app/settings/web-access-settings.test.tsx
index 4753996dfb1..337d02862d8 100644
--- a/apps/desktop/src/app/settings/web-access-settings.test.tsx
+++ b/apps/desktop/src/app/settings/web-access-settings.test.tsx
@@ -87,4 +87,20 @@ describe('WebAccessSettings', () => {
expect(await screen.findByText('Restart needed')).toBeTruthy()
expect(screen.queryByText('Stopped')).toBeNull()
})
+
+ it('shows a web app served on this computer only as local, never as your own URL', async () => {
+ // `webapp.enabled: true` on loopback (the `hermes webapp` setup): reachable from this computer only.
+ renderPane({
+ ...OFF,
+ enabled: true,
+ gateway: { reason: null, state: 'serving', url: 'http://127.0.0.1:9120' },
+ mode: 'local'
+ })
+
+ expect(await screen.findByRole('link', { name: /http:\/\/127\.0\.0\.1:9120/ })).toBeTruthy()
+ expect(screen.getByText(/Only this computer can open it/)).toBeTruthy()
+ expect(screen.queryByText('My own URL')).toBeNull()
+ expect(screen.queryByText(/192\.168\.1\.50/)).toBeNull()
+ expect(screen.getByRole('button', { name: 'Stop' })).toBeTruthy()
+ })
})
diff --git a/apps/desktop/src/app/settings/web-access-settings.tsx b/apps/desktop/src/app/settings/web-access-settings.tsx
index e2fa6bdcef2..e34e277ab23 100644
--- a/apps/desktop/src/app/settings/web-access-settings.tsx
+++ b/apps/desktop/src/app/settings/web-access-settings.tsx
@@ -93,11 +93,15 @@ type FormProps = { queryKey: readonly unknown[]; status: WebAccessStatus; w: Web
function WebAccessForm({ queryKey, status, w }: FormProps): ReactElement {
const queryClient = useQueryClient()
const [busy, setBusy] = useState<'start' | 'stop' | null>(null)
- const [mode, setMode] = useState<WebAccessMode>(status.mode ?? 'lan')
+ const [mode, setMode] = useState<WebAccessMode>(status.mode === 'public' ? 'public' : 'lan')
const [publicUrl, setPublicUrl] = useState(status.public_url)
const phase = phaseOf(status)
const lanUrl = status.lan_address ? `http://${status.lan_address}:${status.port}` : null
- const url = status.mode === 'public' ? status.public_url : (lanUrl ?? '')
+ const localUrl = status.gateway.url ?? `http://127.0.0.1:${status.port}`
+
+ const url =
+ status.mode === 'public' ? status.public_url : status.mode === 'local' ? localUrl : (lanUrl ?? '')
+
const ready = status.nous_signed_in && (mode === 'lan' ? Boolean(lanUrl) : publicUrl.trim().startsWith('https://'))
const apply = (next: WebAccessStatus): void => {
@@ -135,16 +139,19 @@ function WebAccessForm({ queryKey, status, w }: FormProps): ReactElement {
<SectionHeading icon={Network} page title={w.title} />
<p className="mb-4 text-[length:var(--conversation-caption-font-size)] text-(--ui-text-tertiary)">{w.intro}</p>
<SettingsSection aside={<Pill tone={phase === 'serving' ? 'success' : 'muted'}>{pillLabel(phase, busy, w)}</Pill>} icon={Globe} title={w.title}>
- <WhereRow
- lanUrl={lanUrl}
- locked={phase !== 'off' || busy !== null}
- mode={mode}
- onMode={setMode}
- onPublicUrl={setPublicUrl}
- port={status.port}
- publicUrl={publicUrl}
- w={w}
- />
+ {/* A web app served on this computer only has no network address to choose until it stops. */}
+ {status.mode !== 'local' && (
+ <WhereRow
+ lanUrl={lanUrl}
+ locked={phase !== 'off' || busy !== null}
+ mode={mode}
+ onMode={setMode}
+ onPublicUrl={setPublicUrl}
+ port={status.port}
+ publicUrl={publicUrl}
+ w={w}
+ />
+ )}
<ListRow
action={
<Button
@@ -224,7 +231,7 @@ function describe(phase: Phase, status: WebAccessStatus, w: WebAccessTranslation
off: status.nous_signed_in ? w.notRunningDetail : w.needsNous,
pendingOff: w.pendingOff,
pendingOn: w.pendingOn,
- serving: status.mode === 'public' ? w.runningPublic : w.runningLan,
+ serving: status.mode === 'public' ? w.runningPublic : status.mode === 'local' ? w.runningLocal : w.runningLan,
unavailable: w.unavailableDetail(status.gateway.reason ?? '')
}
diff --git a/apps/desktop/src/i18n/ar_settings.ts b/apps/desktop/src/i18n/ar_settings.ts
index c8453c54858..b62f7d837c4 100644
--- a/apps/desktop/src/i18n/ar_settings.ts
+++ b/apps/desktop/src/i18n/ar_settings.ts
@@ -721,6 +721,7 @@ export const arSettings = {
needsNous: 'سجّل الدخول إلى حساب Nous من قسم المزوّدين أولًا.',
runningLan: 'افتح هذا العنوان على جهاز في الشبكة نفسها.',
runningPublic: 'يُقدَّم عبر عنوانك.',
+ runningLocal: 'يمكن فتحه من هذا الحاسوب فقط. أوقفه ثم شغّله من جديد لفتحه من أجهزة أخرى.',
pendingOn: 'تم الحفظ. ستقدّم البوابة تطبيق الويب بعد إعادة تشغيلها.',
pendingOff: 'تم الإيقاف، لكن البوابة تواصل تقديم تطبيق الويب حتى إعادة تشغيلها.',
unavailableDetail: reason => `تعذّر على البوابة تقديم تطبيق الويب: ${reason}`,
diff --git a/apps/desktop/src/i18n/de_gateway_host.ts b/apps/desktop/src/i18n/de_gateway_host.ts
index c8b2a4b10e0..935b586b938 100644
--- a/apps/desktop/src/i18n/de_gateway_host.ts
+++ b/apps/desktop/src/i18n/de_gateway_host.ts
@@ -20,6 +20,7 @@ export const deGatewayHost: GatewayHostTranslations = {
needsNous: 'Melde dich zuerst unter Anbieter bei deinem Nous-Konto an.',
runningLan: 'Öffne diese Adresse auf einem Gerät im selben Netzwerk.',
runningPublic: 'Über deine URL bereitgestellt.',
+ runningLocal: 'Nur dieser Computer kann die Web-App öffnen. Stoppe sie und starte sie erneut, um sie von anderen Geräten aus zu öffnen.',
pendingOn: 'Gespeichert. Das Gateway stellt die Web-App nach seinem Neustart bereit.',
pendingOff: 'Ausgeschaltet, aber das Gateway stellt die Web-App bis zu seinem Neustart weiter bereit.',
unavailableDetail: reason => `Das Gateway konnte die Web-App nicht bereitstellen: ${reason}`,
diff --git a/apps/desktop/src/i18n/en_gateway_host.ts b/apps/desktop/src/i18n/en_gateway_host.ts
index 5ec3b9297f3..ef53604e1c7 100644
--- a/apps/desktop/src/i18n/en_gateway_host.ts
+++ b/apps/desktop/src/i18n/en_gateway_host.ts
@@ -20,6 +20,7 @@ export const enGatewayHost: GatewayHostTranslations = {
needsNous: 'Sign in to your Nous account under Providers first.',
runningLan: 'Open this address on a device on the same network.',
runningPublic: 'Served through your URL.',
+ runningLocal: 'Only this computer can open it. Stop it, then start it again to open it from other devices.',
pendingOn: 'Saved. The gateway serves the web app once it restarts.',
pendingOff: 'Turned off, but the gateway keeps serving the web app until it restarts.',
unavailableDetail: reason => `The gateway couldn't serve the web app: ${reason}`,
diff --git a/apps/desktop/src/i18n/es_gateway_host.ts b/apps/desktop/src/i18n/es_gateway_host.ts
index 1745067dddf..07153d530c1 100644
--- a/apps/desktop/src/i18n/es_gateway_host.ts
+++ b/apps/desktop/src/i18n/es_gateway_host.ts
@@ -21,6 +21,7 @@ export const esGatewayHost: GatewayHostTranslations = {
needsNous: 'Primero inicia sesión en tu cuenta de Nous en Proveedores.',
runningLan: 'Abre esta dirección en un dispositivo de la misma red.',
runningPublic: 'Servido a través de tu URL.',
+ runningLocal: 'Solo este ordenador puede abrirla. Detenla y vuelve a iniciarla para abrirla desde otros dispositivos.',
pendingOn: 'Guardado. El gateway servirá la aplicación web cuando se reinicie.',
pendingOff: 'Desactivado, pero el gateway sigue sirviendo la aplicación web hasta que se reinicie.',
unavailableDetail: reason => `El gateway no pudo servir la aplicación web: ${reason}`,
diff --git a/apps/desktop/src/i18n/fr_gateway_host.ts b/apps/desktop/src/i18n/fr_gateway_host.ts
index f1b9ea3231d..d380b532d4c 100644
--- a/apps/desktop/src/i18n/fr_gateway_host.ts
+++ b/apps/desktop/src/i18n/fr_gateway_host.ts
@@ -20,6 +20,7 @@ export const frGatewayHost: GatewayHostTranslations = {
needsNous: "Connectez-vous d'abord à votre compte Nous dans Fournisseurs.",
runningLan: 'Ouvrez cette adresse sur un appareil du même réseau.',
runningPublic: 'Servi via votre URL.',
+ runningLocal: "Seul cet ordinateur peut ouvrir l'application web. Arrêtez-la, puis relancez-la pour l'ouvrir depuis d'autres appareils.",
pendingOn: "Enregistré. La passerelle servira l'application web après son redémarrage.",
pendingOff: "Désactivé, mais la passerelle continue de servir l'application web jusqu'à son redémarrage.",
unavailableDetail: reason => `La passerelle n'a pas pu servir l'application web : ${reason}`,
diff --git a/apps/desktop/src/i18n/ja_gateway_host.ts b/apps/desktop/src/i18n/ja_gateway_host.ts
index c849b4f895d..e80573e6a68 100644
--- a/apps/desktop/src/i18n/ja_gateway_host.ts
+++ b/apps/desktop/src/i18n/ja_gateway_host.ts
@@ -20,6 +20,7 @@ export const jaGatewayHost: GatewayHostTranslations = {
needsNous: '先に「プロバイダー」で Nous アカウントにサインインしてください。',
runningLan: '同じネットワーク上のデバイスでこのアドレスを開いてください。',
runningPublic: 'あなたの URL 経由で提供中です。',
+ runningLocal: 'このコンピューターからのみ開けます。他のデバイスから開くには、停止してからもう一度起動してください。',
pendingOn: '保存しました。ゲートウェイの再起動後に Web アプリが提供されます。',
pendingOff: 'オフにしましたが、ゲートウェイは再起動するまで Web アプリを提供し続けます。',
unavailableDetail: reason => `ゲートウェイが Web アプリを提供できませんでした: ${reason}`,
diff --git a/apps/desktop/src/i18n/ru_gateway_host.ts b/apps/desktop/src/i18n/ru_gateway_host.ts
index b3c991b2f03..39f354b900e 100644
--- a/apps/desktop/src/i18n/ru_gateway_host.ts
+++ b/apps/desktop/src/i18n/ru_gateway_host.ts
@@ -20,6 +20,7 @@ export const ruGatewayHost: GatewayHostTranslations = {
needsNous: 'Сначала войдите в аккаунт Nous в разделе «Провайдеры».',
runningLan: 'Откройте этот адрес на устройстве в той же сети.',
runningPublic: 'Доступен через ваш URL.',
+ runningLocal: 'Открыть его можно только на этом компьютере. Остановите и снова запустите его, чтобы открыть с других устройств.',
pendingOn: 'Сохранено. Шлюз откроет веб-приложение после перезапуска.',
pendingOff: 'Выключено, но шлюз продолжает открывать веб-приложение до перезапуска.',
unavailableDetail: reason => `Шлюзу не удалось открыть веб-приложение: ${reason}`,
diff --git a/apps/desktop/src/i18n/types_gateway_host.ts b/apps/desktop/src/i18n/types_gateway_host.ts
index fc8823c6e29..6657cc81c5b 100644
--- a/apps/desktop/src/i18n/types_gateway_host.ts
+++ b/apps/desktop/src/i18n/types_gateway_host.ts
@@ -23,6 +23,7 @@ export interface WebAccessTranslations {
needsNous: string
runningLan: string
runningPublic: string
+ runningLocal: string
pendingOn: string
pendingOff: string
unavailableDetail: (reason: string) => string
diff --git a/apps/desktop/src/i18n/zh-hant_settings.ts b/apps/desktop/src/i18n/zh-hant_settings.ts
index 44cb533aa11..04e0683b22a 100644
--- a/apps/desktop/src/i18n/zh-hant_settings.ts
+++ b/apps/desktop/src/i18n/zh-hant_settings.ts
@@ -988,6 +988,7 @@ export const zhHantSettings = {
needsNous: '請先在「供應商」中登入你的 Nous 帳戶。',
runningLan: '在同一網路中的裝置上開啟此網址。',
runningPublic: '透過你的網址提供服務。',
+ runningLocal: '只有這台電腦可以開啟。要從其他裝置開啟,請先停止,再重新啟動。',
pendingOn: '已儲存。閘道重新啟動後將提供網頁應用程式。',
pendingOff: '已關閉,但閘道在重新啟動前仍會繼續提供網頁應用程式。',
unavailableDetail: reason => `閘道無法提供網頁應用程式:${reason}`,
diff --git a/apps/desktop/src/i18n/zh_gateway_host.ts b/apps/desktop/src/i18n/zh_gateway_host.ts
index e519261e00e..46d64df15e8 100644
--- a/apps/desktop/src/i18n/zh_gateway_host.ts
+++ b/apps/desktop/src/i18n/zh_gateway_host.ts
@@ -20,6 +20,7 @@ export const zhGatewayHost: GatewayHostTranslations = {
needsNous: '请先在“提供商”中登录你的 Nous 账户。',
runningLan: '在同一网络中的设备上打开此地址。',
runningPublic: '通过你的网址提供服务。',
+ runningLocal: '只有这台电脑可以打开。要从其他设备打开,请先停止,再重新启动。',
pendingOn: '已保存。网关重启后将提供网页应用。',
pendingOff: '已关闭,但网关在重启前仍会继续提供网页应用。',
unavailableDetail: reason => `网关无法提供网页应用:${reason}`,
diff --git a/hermes_cli/webapp_access.py b/hermes_cli/webapp_access.py
index 57e5353a979..f297bac8529 100644
--- a/hermes_cli/webapp_access.py
+++ b/hermes_cli/webapp_access.py
@@ -174,16 +174,29 @@ def _gateway_state(home: Path) -> dict:
return dict(response["result"])
+def _mode(settings, public_url: str) -> Optional[str]:
+ """Who the configured Webapp serves: ``public`` (its own URL pins the callback and Host),
+ ``lan`` (a wildcard bind), ``local`` (a loopback bind, as ``hermes webapp`` sets it up), or None
+ when it is off."""
+ from gateway.webapp_listener import _is_wildcard
+
+ if not settings.enabled:
+ return None
+ if public_url:
+ return "public"
+ return "lan" if _is_wildcard(settings.host) else "local"
+
+
def access_status() -> dict:
"""Everything the Web Access pane shows, read for the gateway home in scope."""
- from gateway.webapp_listener import _is_wildcard, webapp_settings
+ from gateway.webapp_listener import webapp_settings
home = gateway_home()
settings = webapp_settings(home)
public_url = _configured_public_url(home)
return {
"enabled": settings.enabled,
- "mode": ("lan" if _is_wildcard(settings.host) else "public") if settings.enabled else None,
+ "mode": _mode(settings, public_url),
"port": settings.port,
"gateway": _gateway_state(home),
"lan_address": lan_address(),
diff --git a/locales/_keys.desktop.json b/locales/_keys.desktop.json
index 2ba0cc38e2b..c5cae08f8bc 100644
--- a/locales/_keys.desktop.json
+++ b/locales/_keys.desktop.json
@@ -3544,6 +3544,7 @@
"settings.gateway.webAccess.restartRefused",
"settings.gateway.webAccess.running",
"settings.gateway.webAccess.runningLan",
+ "settings.gateway.webAccess.runningLocal",
"settings.gateway.webAccess.runningPublic",
"settings.gateway.webAccess.start",
"settings.gateway.webAccess.startTimedOut",
diff --git a/tests/hermes_cli/test_webapp_access.py b/tests/hermes_cli/test_webapp_access.py
index 761da1645a3..8e9179f73cf 100644
--- a/tests/hermes_cli/test_webapp_access.py
+++ b/tests/hermes_cli/test_webapp_access.py
@@ -102,3 +102,23 @@ def test_start_without_a_nous_account_writes_and_restarts_nothing(client, restar
assert nous == []
assert restarts == []
assert not _config().get("webapp", {}).get("enabled")
+
+
[email protected](("webapp", "mode"), [
+ ({"enabled": True}, "local"),
+ ({"enabled": True, "host": "::1"}, "local"),
+ ({"enabled": True, "host": "0.0.0.0"}, "lan"),
+ ({"enabled": True, "public_url": "https://hermes.example.test"}, "public"),
+ ({"enabled": False, "host": "0.0.0.0", "public_url": "https://hermes.example.test"}, None),
+])
+def test_status_names_the_mode_the_config_serves(client, webapp, mode):
+ """The pane's mode follows the config: the documented loopback setup (``webapp.enabled: true``)
+ serves this computer only, a wildcard host serves the network, and ``webapp.public_url`` serves
+ the user's own URL. A loopback Webapp is never shown as "My own URL" with no address."""
+ from hermes_cli.config import save_config
+
+ save_config({**_config(), "webapp": webapp})
+
+ status = client.get("/api/webapp-access/status")
+ assert status.status_code == 200, status.text
+ assert status.json()["mode"] == mode