feat: add environment configuration files and update API base URL handling for production
This commit is contained in:
@@ -12,7 +12,15 @@ export class BaseApiClient implements ApiClient {
|
||||
}
|
||||
|
||||
private buildURL(endpoint: string, params?: Record<string, string | number | boolean | undefined>): string {
|
||||
const url = new URL(endpoint, this.baseURL)
|
||||
let url: URL
|
||||
|
||||
if (this.baseURL) {
|
||||
// Full base URL provided
|
||||
url = new URL(endpoint, this.baseURL)
|
||||
} else {
|
||||
// Use relative URL (for reverse proxy)
|
||||
url = new URL(endpoint, window.location.origin)
|
||||
}
|
||||
|
||||
if (params) {
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
@@ -22,7 +30,7 @@ export class BaseApiClient implements ApiClient {
|
||||
})
|
||||
}
|
||||
|
||||
return url.toString()
|
||||
return this.baseURL ? url.toString() : url.pathname + url.search
|
||||
}
|
||||
|
||||
private async request<T>(
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
// API Configuration
|
||||
const getApiBaseUrl = () => {
|
||||
// If VITE_API_BASE_URL is explicitly set to empty string, use relative URLs
|
||||
if (import.meta.env.VITE_API_BASE_URL === '') {
|
||||
return '' // Use relative URLs (reverse proxy handles routing)
|
||||
}
|
||||
// In production with reverse proxy, use relative URL (same origin)
|
||||
if (import.meta.env.PROD) {
|
||||
return '' // Use relative URLs in production (reverse proxy handles routing)
|
||||
}
|
||||
// Use environment variable in development, fallback to localhost
|
||||
return import.meta.env.VITE_API_BASE_URL || 'http://localhost:8000'
|
||||
}
|
||||
|
||||
export const API_CONFIG = {
|
||||
BASE_URL: 'http://localhost:8000',
|
||||
BASE_URL: getApiBaseUrl(),
|
||||
TIMEOUT: 30000, // 30 seconds
|
||||
RETRY_ATTEMPTS: 1,
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { apiClient } from '../client'
|
||||
import { API_CONFIG } from '../config'
|
||||
|
||||
export class FilesService {
|
||||
|
||||
Reference in New Issue
Block a user