Skip to content

Commit e76698f

Browse files
committed
fix: skip REST API calls entirely on standalone PWA
1 parent ec693ff commit e76698f

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

src/bridges/user/web/frontend/main.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,10 @@ function sendAction(action: Action): void {
143143
}
144144

145145
async function refreshState(): Promise<void> {
146-
try {
147-
const [agents, rooms] = await Promise.all([fetchAgents(), fetchRooms()]);
148-
state.setAgents(agents);
149-
state.setRooms(rooms);
150-
} catch {
151-
// REST API unavailable (standalone PWA) — MeshClient provides state
152-
return;
153-
}
146+
if (!isLocalServer) return;
147+
const [agents, rooms] = await Promise.all([fetchAgents(), fetchRooms()]);
148+
state.setAgents(agents);
149+
state.setRooms(rooms);
154150
}
155151

156152
async function onJoinRoom(roomId: string): Promise<void> {
@@ -160,9 +156,11 @@ async function onJoinRoom(roomId: string): Promise<void> {
160156

161157
sendAction({ action: "join_room", room: roomId });
162158

163-
// Load history
164-
const messages = await fetchRoomMessages(roomId);
165-
state.setMessages(messages.map(roomMessageToDisplay));
159+
// Load history (skip REST fetch on standalone PWA — no server)
160+
if (isLocalServer) {
161+
const messages = await fetchRoomMessages(roomId);
162+
state.setMessages(messages.map(roomMessageToDisplay));
163+
}
166164
addMessage({ type: "system", text: `Joined ${roomId}` });
167165
}
168166

@@ -282,8 +280,11 @@ const deepLink = parseDeepLink(location.search);
282280

283281
// Only connect the direct server WebSocket when served from localhost.
284282
// On GitHub Pages / standalone deployments, only MeshClient is used.
285-
const localPattern = /^(localhost|127\.\d+\.\d+\.\d+)(:\d+)?$/;
286-
if (localPattern.test(location.host)) {
283+
/** Whether the page is served from a local mesh server (vs standalone PWA). */
284+
const isLocalServer = /^(localhost|127\.\d+\.\d+\.\d+)(:\d+)?$/.test(
285+
location.host,
286+
);
287+
if (isLocalServer) {
287288
ws.connect();
288289
}
289290

0 commit comments

Comments
 (0)