Skip to content

Commit 33f1e28

Browse files
author
martin
committed
Fix API URL for production - use relative /api path when deployed
1 parent 19e534b commit 33f1e28

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

frontend/src/api/axios.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
import axios from 'axios';
22

3-
const API_URL = process.env.REACT_APP_API_URL || 'http://localhost:8082/api';
3+
// In production, use relative URL (nginx proxies /api to backend)
4+
// In development, use localhost with explicit port
5+
const getApiUrl = () => {
6+
if (process.env.REACT_APP_API_URL) {
7+
return process.env.REACT_APP_API_URL;
8+
}
9+
// Check if we're in production (served from a domain, not localhost dev server)
10+
if (typeof window !== 'undefined' &&
11+
window.location.hostname !== 'localhost' &&
12+
window.location.hostname !== '127.0.0.1') {
13+
return '/api';
14+
}
15+
return 'http://localhost:8082/api';
16+
};
17+
18+
const API_URL = getApiUrl();
419

520
const axiosInstance = axios.create({
621
baseURL: API_URL,

0 commit comments

Comments
 (0)