Skip to content

Commit 8fcb3fa

Browse files
committed
fix: make frontend API URLs dynamic using window.location.hostname
1 parent 729a8b9 commit 8fcb3fa

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

dashboard-frontend/src/services/api.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ declare global {
1010
}
1111
}
1212

13-
const API_BASE = import.meta.env.VITE_API_URL || "http://localhost:5003";
13+
const getBaseUrl = (port: number) => {
14+
if (typeof window !== "undefined") {
15+
return `http://${window.location.hostname}:${port}`;
16+
}
17+
return `http://localhost:${port}`;
18+
};
19+
20+
const API_BASE = import.meta.env.VITE_API_URL || getBaseUrl(5003);
21+
const PRODUCER_BASE = getBaseUrl(5001);
1422

1523
interface JobResponse {
1624
id?: string;
@@ -114,7 +122,7 @@ export const getCompletedJobs = async (): Promise<CompletedJobsResponse> => {
114122
// Submit New Job
115123
export const submitReport = async (reportType: string, data: object) => {
116124
const response = await axios.post(
117-
"http://localhost:5001/api/v1/reports/generate",
125+
`${PRODUCER_BASE}/api/v1/reports/generate`,
118126
{ reportType, data },
119127
{ headers: { "Content-Type": "application/json" } }
120128
);

infra/docker-compose.prod.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ services:
6262
ports: [ "5004:5004" ]
6363
environment:
6464
- FRONTEND_PORT=5004
65-
- VITE_API_URL=http://localhost:5003
6665
- NODE_ENV=production
6766
depends_on: [ dashboard-api ]
6867

0 commit comments

Comments
 (0)