-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathconfig.ts
More file actions
56 lines (48 loc) · 1.94 KB
/
config.ts
File metadata and controls
56 lines (48 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// API Configuration
const getApiBaseUrl = () => {
// In production on Vercel, use the same domain with /api
if (typeof window !== 'undefined' && window.location.hostname.includes('vercel.app')) {
return `${window.location.origin}/api`;
}
// Otherwise use environment variable or default to localhost
return process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:8000';
};
const apiBaseUrl = getApiBaseUrl();
// Debug logging in development
if (typeof window !== 'undefined' && process.env.NODE_ENV === 'development') {
console.log('API Base URL:', apiBaseUrl);
}
// Validation: warn if the API URL looks incorrect
if (typeof window !== 'undefined') {
const currentDomain = window.location.origin;
// If API URL is the same as frontend URL (without /api), warn user
if (apiBaseUrl === currentDomain) {
console.warn(
'⚠️ Warning: NEXT_PUBLIC_API_BASE_URL is set to the same URL as your frontend.',
'\n Current value:', apiBaseUrl,
'\n If your backend is deployed separately, use that URL.',
'\n If using Vercel API routes, add /api to the end.',
'\n Examples:',
'\n - Separate backend: https://your-backend-project.vercel.app',
'\n - API routes: https://vectorless-chatbot.vercel.app/api'
);
}
// If it looks like a frontend-only URL (no api subdomain or /api path)
if (apiBaseUrl.includes('vercel.app') &&
!apiBaseUrl.includes('/api') &&
!apiBaseUrl.includes('api.') &&
!apiBaseUrl.includes('-api') &&
!apiBaseUrl.includes('-backend')) {
console.warn(
'⚠️ Warning: NEXT_PUBLIC_API_BASE_URL might be incorrect.',
'\n Current value:', apiBaseUrl,
'\n For Vercel deployments, consider:',
'\n - Separate backend project: https://your-backend-project.vercel.app',
'\n - API routes in same project: https://your-project.vercel.app/api'
);
}
}
const config = {
apiBaseUrl,
};
export default config;