Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(ui,server): make /settings redirect browser nav to SPA settings page

cyh3b9c23e10d69
diff --git a/tests/test_ui_remote_access_auth.py b/tests/test_ui_remote_access_auth.py
index 18c71ede6..78151572d 100644
--- a/tests/test_ui_remote_access_auth.py
+++ b/tests/test_ui_remote_access_auth.py
@@ -801,3 +801,39 @@ def test_setup_host_with_reverse_proxy_header_is_not_local(monkeypatch, tmp_path
assert response.status_code == 503
assert response.get_json()["error"] == "remote_access_host_mismatch"
+
+
+def test_settings_get_redirects_browser_navigation_to_spa(monkeypatch, tmp_path):
+ """A browser bookmark / hard refresh of /settings sends Accept: text/html
+ and must be redirected to the SPA settings page rather than receiving the
+ JSON API payload, so the user lands in the UI as expected.
+ """
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ _save_config(tmp_path)
+
+ response = app.test_client().get(
+ "/settings",
+ base_url="http://127.0.0.1:5123",
+ headers={"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"},
+ follow_redirects=False,
+ )
+
+ assert response.status_code in (301, 302, 303, 307, 308)
+ assert response.headers["Location"].endswith("/settings/service")
+
+
+def test_settings_get_returns_json_for_fetch_callers(monkeypatch, tmp_path):
+ """fetch() from the SPA hits /settings without an explicit text/html in
+ Accept; the handler must keep returning JSON so getSettings() works.
+ """
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ _save_config(tmp_path)
+
+ response = app.test_client().get(
+ "/settings",
+ base_url="http://127.0.0.1:5123",
+ headers={"Accept": "*/*"},
+ )
+
+ assert response.status_code == 200
+ assert response.is_json
diff --git a/ui/src/App.tsx b/ui/src/App.tsx
index 318f707b7..e90d3e97a 100644
--- a/ui/src/App.tsx
+++ b/ui/src/App.tsx
@@ -71,7 +71,9 @@ function AppRoutes() {
<Route path="/channels" element={<Navigate to="/groups" replace />} />
<Route path="/users" element={<UserList />} />
<Route path="/logs" element={<SettingsLogsPage standalone />} />
- <Route path="/settings" element={<Navigate to="/settings/service" replace />} />
+ {/* No client-side route at /settings: Flask owns GET /settings as a
+ JSON API, so a hard refresh would hit the API instead of the SPA.
+ The Flask handler redirects browser-Accept hits to /settings/service. */}
<Route path="/settings/service" element={<SettingsServicePage />} />
<Route path="/settings/platforms" element={<SettingsPlatformsPage />} />
<Route path="/settings/backends" element={<SettingsBackendsPage />} />
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 242baa3ca..f38937dce 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -15,7 +15,7 @@ from pathlib import Path
from typing import Any
from urllib.parse import quote, unquote, urlparse, urlsplit, urlunsplit
-from flask import Flask, request, jsonify, send_file, Response
+from flask import Flask, request, jsonify, redirect, send_file, Response
from config import paths
from config.v2_config import CONFIG_LOCK, V2Config
@@ -710,6 +710,14 @@ def platforms_get():
@app.route("/settings", methods=["GET"])
def settings_get():
+ # /settings doubles as a backend JSON API and a user-facing URL the SPA
+ # owns (it lives under /settings/<page>). Browser navigations send
+ # Accept: text/html..., while fetch() callers from the SPA send Accept:
+ # */* (no explicit text/html), so we can distinguish the two and redirect
+ # bookmarked / hard-refreshed browser hits to the canonical settings page
+ # instead of serving raw JSON.
+ if "text/html" in request.headers.get("Accept", ""):
+ return redirect("/settings/service")
from vibe import api
return jsonify(api.get_settings(request.args.get("platform") or None))