Spaces:
Sleeping
Sleeping
tiffank1802 commited on
Commit ·
db54c41
1
Parent(s): 7b36781
Fix API URL: use relative path for production (HF Spaces)
Browse files- Changed API_URL logic to detect localhost vs production
- In production, uses relative '/api' path instead of hardcoded localhost
- Fixes 'load error' when running simulation on HF Spaces
frontend/src/api.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
// API pour les simulations existantes (thermique)
|
| 4 |
export const api = {
|
|
@@ -22,7 +36,9 @@ export const api = {
|
|
| 22 |
},
|
| 23 |
|
| 24 |
getResultImage: (simulation) => {
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
return `${baseUrl}${simulation.result_image_path}`;
|
| 27 |
}
|
| 28 |
};
|
|
|
|
| 1 |
+
// Use relative URL for production (HF Spaces serves frontend + backend from same origin)
|
| 2 |
+
// Use localhost for development when VITE_API_URL is not set and we're on localhost
|
| 3 |
+
const getApiUrl = () => {
|
| 4 |
+
if (import.meta.env.VITE_API_URL) {
|
| 5 |
+
return import.meta.env.VITE_API_URL;
|
| 6 |
+
}
|
| 7 |
+
// In production (HF Spaces), use relative URL
|
| 8 |
+
// In development (localhost), use localhost:8000
|
| 9 |
+
if (typeof window !== 'undefined' && window.location.hostname === 'localhost') {
|
| 10 |
+
return 'http://localhost:8000/api';
|
| 11 |
+
}
|
| 12 |
+
return '/api'; // Relative URL for production
|
| 13 |
+
};
|
| 14 |
+
|
| 15 |
+
const API_URL = getApiUrl();
|
| 16 |
|
| 17 |
// API pour les simulations existantes (thermique)
|
| 18 |
export const api = {
|
|
|
|
| 36 |
},
|
| 37 |
|
| 38 |
getResultImage: (simulation) => {
|
| 39 |
+
// In production, use current origin; in dev, use localhost:8000
|
| 40 |
+
const baseUrl = import.meta.env.VITE_API_URL
|
| 41 |
+
|| (window.location.hostname === 'localhost' ? 'http://localhost:8000' : window.location.origin);
|
| 42 |
return `${baseUrl}${simulation.result_image_path}`;
|
| 43 |
}
|
| 44 |
};
|
static/assets/{index-ds7zB4Sa.js → index-BiDAFXxT.js}
RENAMED
|
The diff for this file is too large to render.
See raw diff
|
|
|
static/assets/index-DOJBTpfK.js
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
static/assets/index-DYM3EwRh.css
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
.app{max-width:1200px;margin:0 auto;padding:20px;font-family:system-ui,-apple-system,sans-serif}header{text-align:center;margin-bottom:30px}main{display:grid;grid-template-columns:1fr 1fr;gap:20px}.simulation-form,.simulation-list,.result-section{background:#f5f5f5;padding:20px;border-radius:8px}.form-group{margin-bottom:15px}.form-group label{display:block;margin-bottom:5px;font-weight:700}.form-group input[type=text]{width:100%;padding:8px;border:1px solid #ddd;border-radius:4px;box-sizing:border-box}.form-group input[type=range]{width:100%}button{background:#007bff;color:#fff;border:none;padding:10px 20px;border-radius:4px;cursor:pointer;width:100%;font-size:1rem}button:disabled{background:#ccc;cursor:not-allowed}table{width:100%;border-collapse:collapse}th,td{padding:10px;text-align:left;border-bottom:1px solid #ddd}tr:hover{cursor:pointer;background:#e9e9e9}.status{padding:4px 8px;border-radius:4px;font-size:.9em}.status-completed{background:#d4edda;color:#155724}.status-running{background:#fff3cd;color:#856404}.status-failed{background:#f8d7da;color:#721c24}.status-pending{background:#e2e3e5;color:#383d41}.result-image img{max-width:100%;border-radius:4px}.error{background:#f8d7da;color:#721c24;padding:10px;border-radius:4px;margin-bottom:15px}.result-section{grid-column:1 / -1}@media (max-width: 768px){main{grid-template-columns:1fr}}
|
|
|
|
|
|
static/index.html
CHANGED
|
@@ -3,11 +3,11 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
-
<title>
|
| 7 |
-
<script type="module" crossorigin src="/
|
| 8 |
-
<link rel="stylesheet" crossorigin href="/
|
| 9 |
</head>
|
| 10 |
<body>
|
| 11 |
<div id="root"></div>
|
| 12 |
</body>
|
| 13 |
-
</html>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Simulation FEniCS</title>
|
| 7 |
+
<script type="module" crossorigin src="/assets/index-BiDAFXxT.js"></script>
|
| 8 |
+
<link rel="stylesheet" crossorigin href="/assets/index-WlaHFykx.css">
|
| 9 |
</head>
|
| 10 |
<body>
|
| 11 |
<div id="root"></div>
|
| 12 |
</body>
|
| 13 |
+
</html>
|