Álvaro Valenzuela Valdes commited on
Commit
e644ec6
·
1 Parent(s): 9023054

fix: Dynamic API detection and robust Nginx proxy rules

Browse files
Files changed (2) hide show
  1. frontend/lib/api.ts +10 -1
  2. nginx.conf +2 -4
frontend/lib/api.ts CHANGED
@@ -1,6 +1,15 @@
1
  import type { AnalysisHistoryItem, AnalysisResult, CompanyProfile, Tender } from "./types";
2
 
3
- const API_BASE = process.env.NEXT_PUBLIC_API_BASE ?? "http://localhost:8000";
 
 
 
 
 
 
 
 
 
4
 
5
  const jsonHeaders = {
6
  "Content-Type": "application/json",
 
1
  import type { AnalysisHistoryItem, AnalysisResult, CompanyProfile, Tender } from "./types";
2
 
3
+ const getApiBase = () => {
4
+ if (process.env.NEXT_PUBLIC_API_BASE) return process.env.NEXT_PUBLIC_API_BASE;
5
+ if (typeof window !== "undefined") {
6
+ // If we are in a Hugging Face Space, we need to ensure we point to the right origin
7
+ return window.location.origin;
8
+ }
9
+ return "http://localhost:8000";
10
+ };
11
+
12
+ const API_BASE = getApiBase();
13
 
14
  const jsonHeaders = {
15
  "Content-Type": "application/json",
nginx.conf CHANGED
@@ -12,15 +12,13 @@ server {
12
  }
13
 
14
  location /api {
15
- proxy_pass http://localhost:8000/api;
16
  proxy_set_header Host $host;
17
  proxy_set_header X-Real-IP $remote_addr;
18
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19
- proxy_set_header X-Forwarded-Proto $scheme;
20
  }
21
 
22
  location /health {
23
- proxy_pass http://localhost:8000/health;
24
  proxy_set_header Host $host;
25
  }
26
  }
 
12
  }
13
 
14
  location /api {
15
+ proxy_pass http://127.0.0.1:8000;
16
  proxy_set_header Host $host;
17
  proxy_set_header X-Real-IP $remote_addr;
 
 
18
  }
19
 
20
  location /health {
21
+ proxy_pass http://127.0.0.1:8000/api/health;
22
  proxy_set_header Host $host;
23
  }
24
  }