Skip to content

Commit df550c2

Browse files
committed
fix(playground): recompute all UI state on selection change, allow localhost and 127.0.0.1 origins
1 parent c49513f commit df550c2

2 files changed

Lines changed: 22 additions & 18 deletions

File tree

packages/moss-cli/src/moss_cli/commands/playground.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ def _check_api_request(self) -> bool:
6262
self._send_json(403, {"error": "Forbidden: invalid or missing token"})
6363
return False
6464
host = self.headers.get("Host", "")
65-
if host and host != self._server_host and host != self._server_host.replace("127.0.0.1", "localhost"):
65+
allowed_hosts = {self._server_host, self._server_host.replace("127.0.0.1", "localhost")}
66+
if host and host not in allowed_hosts:
6667
self._send_json(403, {"error": "Forbidden: invalid Host header"})
6768
return False
6869
origin = self.headers.get("Origin", "")
69-
if origin and origin != f"http://{self._server_host}":
70+
allowed_origins = {f"http://{h}" for h in allowed_hosts}
71+
if origin and origin not in allowed_origins:
7072
self._send_json(403, {"error": "Forbidden: invalid Origin"})
7173
return False
7274
return True

packages/moss-cli/src/moss_cli/playground/index.html

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,19 @@ <h1>Moss <span>Playground</span></h1>
193193

194194
function updateLoadBtn() {
195195
const name = select.value;
196-
loadBtn.disabled = !name || name === currentIndex;
197-
if (name !== currentIndex && currentIndex) {
198-
searchInput.disabled = true;
199-
topkInput.disabled = true;
200-
alphaSlider.disabled = true;
196+
const isLoaded = name === currentIndex;
197+
loadBtn.disabled = !name || isLoaded;
198+
loadBtn.innerHTML = isLoaded ? '&#10003; Loaded' : 'Load Index';
199+
loadBtn.className = isLoaded ? 'btn btn-success' : 'btn btn-primary';
200+
searchInput.disabled = !isLoaded;
201+
topkInput.disabled = !isLoaded;
202+
alphaSlider.disabled = !isLoaded;
203+
if (isLoaded) {
204+
loadStatus.className = 'status-box status-success';
205+
loadStatus.textContent = 'Index loaded into server memory';
206+
loadStatus.classList.remove('hidden');
207+
} else {
208+
loadStatus.classList.add('hidden');
201209
}
202210
}
203211

@@ -249,22 +257,16 @@ <h1>Moss <span>Playground</span></h1>
249257
}
250258
if (loadReqId !== requestId || select.value !== name) return;
251259
currentIndex = name;
252-
loadBtn.innerHTML = '&#10003; Loaded';
253-
loadBtn.className = 'btn btn-success';
254-
loadBtn.disabled = false;
255-
loadStatus.className = 'status-box status-success';
256-
loadStatus.textContent = 'Index loaded into server memory';
257-
searchInput.disabled = false;
260+
updateLoadBtn();
258261
searchInput.focus();
259-
topkInput.disabled = false;
260-
alphaSlider.disabled = false;
261262
} catch (e) {
262263
if (loadReqId !== requestId) return;
263264
console.error('loadIndex failed:', e);
264265
currentIndex = null;
265-
loadBtn.innerHTML = 'Load Index';
266-
loadBtn.className = 'btn btn-primary';
267-
loadBtn.disabled = false;
266+
updateLoadBtn();
267+
loadStatus.classList.remove('hidden');
268+
loadStatus.className = 'status-box status-error';
269+
loadStatus.textContent = `Failed: ${e.message || e}`;
268270
loadStatus.className = 'status-box status-error';
269271
loadStatus.textContent = `Failed: ${e.message || e}`;
270272
} finally {

0 commit comments

Comments
 (0)