Spaces:
Sleeping
Sleeping
Commit ·
1c495e4
1
Parent(s): 300d59f
Fix Spaces API endpoint resolution in frontend.
Browse filesReplace hardcoded localhost API/WS URLs with environment-aware resolution so production requests use same-origin in Hugging Face Spaces.
Made-with: Cursor
openenv-polypharmacy/frontend/src/App.jsx
CHANGED
|
@@ -1,7 +1,22 @@
|
|
| 1 |
import { useEffect, useMemo, useRef, useState } from "react";
|
| 2 |
|
| 3 |
-
|
| 4 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
const TASKS = ["easy_screening", "budgeted_screening", "complex_tradeoff"];
|
| 6 |
|
| 7 |
async function apiPost(path, body) {
|
|
|
|
| 1 |
import { useEffect, useMemo, useRef, useState } from "react";
|
| 2 |
|
| 3 |
+
function resolveApiBase() {
|
| 4 |
+
const explicitBase = import.meta.env.VITE_API_BASE;
|
| 5 |
+
if (explicitBase) return explicitBase.replace(/\/$/, "");
|
| 6 |
+
|
| 7 |
+
const host = window.location.hostname;
|
| 8 |
+
const isLocal =
|
| 9 |
+
host === "localhost" || host === "127.0.0.1" || host === "0.0.0.0";
|
| 10 |
+
|
| 11 |
+
// In local Vite dev, backend runs on :7860. In Spaces/prod, serve same-origin.
|
| 12 |
+
if (isLocal && window.location.port === "5173") {
|
| 13 |
+
return "http://localhost:7860";
|
| 14 |
+
}
|
| 15 |
+
return window.location.origin.replace(/\/$/, "");
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
const API_BASE = resolveApiBase();
|
| 19 |
+
const WS_URL = `${API_BASE.replace(/^http/, "ws")}/ws`;
|
| 20 |
const TASKS = ["easy_screening", "budgeted_screening", "complex_tradeoff"];
|
| 21 |
|
| 22 |
async function apiPost(path, body) {
|