Vineela Gampa commited on
Commit
f8c2675
·
unverified ·
1 Parent(s): 8cd0f60

fixes for api url

Browse files
Files changed (1) hide show
  1. web/analyzer.html +26 -3
web/analyzer.html CHANGED
@@ -189,7 +189,30 @@
189
  </li>
190
  </ul>
191
  </nav>
192
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  <script>
194
  const hamburger = document.getElementById("hamburger");
195
  const mobileMenu = document.getElementById("mobile-menu");
@@ -470,7 +493,7 @@
470
 
471
  let data;
472
  try {
473
- const res = await fetch("http://localhost:9000/analyze/", {
474
  method: "POST",
475
  body: formData,
476
  });
@@ -525,7 +548,7 @@
525
 
526
  async function postReportToBackend(report) {
527
  try {
528
- const response = await fetch('http://localhost:9000/save_report/', {
529
  method: 'POST',
530
  headers: {
531
  'Content-Type': 'application/json',
 
189
  </li>
190
  </ul>
191
  </nav>
192
+ <script>
193
+ (function () {
194
+ const isLocal = /^(localhost|127\.0\.0\.1)$/.test(location.hostname);
195
+
196
+ // Optional overrides
197
+ const qs = new URLSearchParams(location.search);
198
+ const override = qs.get("api"); // e.g. ?api=http://localhost:9000
199
+ const saved = localStorage.getItem("API_BASE"); // remember last override
200
+
201
+ const base =
202
+ override ||
203
+ saved ||
204
+ // Local dev: call FastAPI on 8000; HF: use same origin (works from / or /proxy/8002)
205
+ (isLocal ? "http://localhost:8000" : location.origin);
206
+
207
+ if (override) localStorage.setItem("API_BASE", override);
208
+
209
+ window.API_BASE = base.replace(/\/$/, ""); // trim trailing slash
210
+ // helper to build URLs without double slashes
211
+ window.api = (path) =>
212
+ window.API_BASE + (path.startsWith("/") ? path : "/" + path);
213
+ })();
214
+ </script>
215
+
216
  <script>
217
  const hamburger = document.getElementById("hamburger");
218
  const mobileMenu = document.getElementById("mobile-menu");
 
493
 
494
  let data;
495
  try {
496
+ const res = await fetch(api("analyze/"), {
497
  method: "POST",
498
  body: formData,
499
  });
 
548
 
549
  async function postReportToBackend(report) {
550
  try {
551
+ const response = await fetch(api('save_report/'), {
552
  method: 'POST',
553
  headers: {
554
  'Content-Type': 'application/json',