Álvaro Valenzuela Valdes commited on
Commit ·
aca6b8f
1
Parent(s): 466f6fd
fix: ensure Nginx config is enabled and simplify API base detection
Browse files- Dockerfile +1 -0
- frontend/lib/api.ts +8 -30
Dockerfile
CHANGED
|
@@ -40,6 +40,7 @@ COPY --from=frontend-builder /app/frontend/node_modules ./frontend/node_modules
|
|
| 40 |
|
| 41 |
# Nginx Config
|
| 42 |
COPY nginx.conf /etc/nginx/sites-available/default
|
|
|
|
| 43 |
|
| 44 |
# Start Script
|
| 45 |
COPY start.sh .
|
|
|
|
| 40 |
|
| 41 |
# Nginx Config
|
| 42 |
COPY nginx.conf /etc/nginx/sites-available/default
|
| 43 |
+
RUN ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
|
| 44 |
|
| 45 |
# Start Script
|
| 46 |
COPY start.sh .
|
frontend/lib/api.ts
CHANGED
|
@@ -4,43 +4,21 @@ import type { AnalysisHistoryItem, AnalysisResult, CompanyProfile, Tender, Purch
|
|
| 4 |
export function getAPIBase(): string {
|
| 5 |
// 1. Explicit env var (highest priority)
|
| 6 |
if (process.env.NEXT_PUBLIC_API_BASE) {
|
| 7 |
-
console.log('[API] Using explicit NEXT_PUBLIC_API_BASE:', process.env.NEXT_PUBLIC_API_BASE);
|
| 8 |
return process.env.NEXT_PUBLIC_API_BASE;
|
| 9 |
}
|
| 10 |
|
| 11 |
-
|
| 12 |
-
if (typeof window === 'undefined') {
|
| 13 |
-
return '';
|
| 14 |
-
}
|
| 15 |
|
| 16 |
const hostname = window.location.hostname;
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
// On HF Spaces, we use relative paths because we run Nginx as a proxy
|
| 22 |
-
// to both the frontend and backend in the same container.
|
| 23 |
-
console.log('[API] Hugging Face Space detected. Using relative paths.');
|
| 24 |
-
return '';
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
// 3. Vercel/Production detection
|
| 28 |
-
if (hostname.includes('vercel.app')) {
|
| 29 |
-
const backendUrl = process.env.REACT_APP_API_BASE || `${protocol}//${hostname.replace('andesai', 'andesai-api')}`;
|
| 30 |
-
console.log('[API] Vercel environment detected. Using:', backendUrl);
|
| 31 |
-
return backendUrl;
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
// 4. GitHub Pages + external API
|
| 35 |
-
if (hostname.includes('github.io') || hostname.includes('github.dev')) {
|
| 36 |
-
const backendUrl = process.env.REACT_APP_API_BASE || 'https://andesai-backend.fly.dev';
|
| 37 |
-
console.log('[API] GitHub Pages detected. Using:', backendUrl);
|
| 38 |
-
return backendUrl;
|
| 39 |
}
|
| 40 |
|
| 41 |
-
//
|
| 42 |
-
|
| 43 |
-
return '
|
| 44 |
}
|
| 45 |
|
| 46 |
const API_BASE = getAPIBase();
|
|
|
|
| 4 |
export function getAPIBase(): string {
|
| 5 |
// 1. Explicit env var (highest priority)
|
| 6 |
if (process.env.NEXT_PUBLIC_API_BASE) {
|
|
|
|
| 7 |
return process.env.NEXT_PUBLIC_API_BASE;
|
| 8 |
}
|
| 9 |
|
| 10 |
+
if (typeof window === 'undefined') return '';
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
const hostname = window.location.hostname;
|
| 13 |
+
|
| 14 |
+
// 2. Local development detection
|
| 15 |
+
if (hostname === 'localhost' || hostname === '127.0.0.1') {
|
| 16 |
+
return 'http://localhost:8000';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
}
|
| 18 |
|
| 19 |
+
// 3. For HF Spaces and production, we use relative paths handled by Nginx proxy
|
| 20 |
+
// This is the most robust way to handle both internal and external traffic
|
| 21 |
+
return '';
|
| 22 |
}
|
| 23 |
|
| 24 |
const API_BASE = getAPIBase();
|