|
9 | 9 | These helpers return data; the components own the rendering. */ |
10 | 10 | (function () { |
11 | 11 | const ORIGIN = window.location.origin; |
| 12 | + // API base: same-origin by default (local dev + the monolith deploy). When the |
| 13 | + // frontend is hosted separately, the page sets window.SPECTRARAG_API_BASE to the |
| 14 | + // API service URL (via a local-only config.js) and every call routes there. |
| 15 | + const API = window.SPECTRARAG_API_BASE || ORIGIN; |
12 | 16 |
|
13 | 17 | // The real, supported model slate (mirrors the prior chat's <select>). |
14 | 18 | // The ":free" entries are the demo chain's models, selectable here so a |
|
38 | 42 | } |
39 | 43 |
|
40 | 44 | function pageImageUrl(paperId, page) { |
41 | | - return `${ORIGIN}/pages/${encodeURIComponent(paperId)}/${encodeURIComponent(paperId)}_p${page}.png`; |
| 45 | + return `${API}/pages/${encodeURIComponent(paperId)}/${encodeURIComponent(paperId)}_p${page}.png`; |
42 | 46 | } |
43 | 47 |
|
44 | 48 | // Pre-rendered figure/table thumbnail (scripts/render_figure_thumbs.py). The |
|
47 | 51 | // full-page CSS-crop when a thumb is absent (e.g. a freshly uploaded paper). |
48 | 52 | function figThumbUrl(paperId, chunkId) { |
49 | 53 | const safe = chunkId.replace(/:/g, "_"); |
50 | | - return `${ORIGIN}/pages/${encodeURIComponent(paperId)}/thumbs/${encodeURIComponent(safe)}.webp`; |
| 54 | + return `${API}/pages/${encodeURIComponent(paperId)}/thumbs/${encodeURIComponent(safe)}.webp`; |
51 | 55 | } |
52 | 56 |
|
53 | 57 | async function loadPapers() { |
54 | 58 | try { |
55 | | - const r = await fetch("/papers"); |
| 59 | + const r = await fetch(`${API}/papers`); |
56 | 60 | return r.ok ? await r.json() : []; |
57 | 61 | } catch { |
58 | 62 | return []; |
|
61 | 65 |
|
62 | 66 | async function loadHealth() { |
63 | 67 | try { |
64 | | - const r = await fetch("/health"); |
| 68 | + const r = await fetch(`${API}/health`); |
65 | 69 | return await r.json(); |
66 | 70 | } catch { |
67 | 71 | return {}; |
|
72 | 76 | // docling role/label. Used by the Figures gallery and the corpus counts. |
73 | 77 | async function loadFigures(limit = 1000) { |
74 | 78 | try { |
75 | | - const r = await fetch(`/figures?limit=${limit}`); |
| 79 | + const r = await fetch(`${API}/figures?limit=${limit}`); |
76 | 80 | return r.ok ? await r.json() : []; |
77 | 81 | } catch { |
78 | 82 | return []; |
|
105 | 109 | if (!apiKey) { |
106 | 110 | throw new Error("Agentic search runs server-side and needs your OpenRouter key."); |
107 | 111 | } |
108 | | - const res = await fetch("/query/dci", { |
| 112 | + const res = await fetch(`${API}/query/dci`, { |
109 | 113 | method: "POST", |
110 | 114 | headers: { "Content-Type": "application/json", "X-OpenRouter-Key": apiKey }, |
111 | 115 | body: JSON.stringify(body), |
|
124 | 128 | // but say which one is happening; give the permanent case a short budget. |
125 | 129 | const start = performance.now(); |
126 | 130 | while (true) { |
127 | | - const res = await fetch("/query", { |
| 131 | + const res = await fetch(`${API}/query`, { |
128 | 132 | method: "POST", |
129 | 133 | headers: { "Content-Type": "application/json" }, |
130 | 134 | body: JSON.stringify(body), |
|
444 | 448 | // server-side — the browser only sends messages. A 429 means the shared |
445 | 449 | // demo quota ran out; callers surface the bring-your-own-key prompt. |
446 | 450 | async function streamDemoChat(messages, onDelta) { |
447 | | - const res = await fetch("/demo/chat", { |
| 451 | + const res = await fetch(`${API}/demo/chat`, { |
448 | 452 | method: "POST", |
449 | 453 | headers: { "Content-Type": "application/json" }, |
450 | 454 | body: JSON.stringify({ messages }), |
|
507 | 511 | async function ingestPdf(file) { |
508 | 512 | const form = new FormData(); |
509 | 513 | form.append("file", file); |
510 | | - const res = await fetch("/ingest", { method: "POST", body: form }); |
| 514 | + const res = await fetch(`${API}/ingest`, { method: "POST", body: form }); |
511 | 515 | if (!res.ok) { |
512 | 516 | let detail = await res.text(); |
513 | 517 | try { detail = JSON.parse(detail).detail || detail; } catch { /* keep raw text */ } |
|
0 commit comments