fix: require REACT_APP_API_URL in production, throw clear error if missing
This commit is contained in:
@@ -77,8 +77,14 @@ class HallucinationDetectorService {
|
||||
private baseUrl: string;
|
||||
|
||||
constructor() {
|
||||
// Consistent API URL pattern - no hardcoded localhost fallback
|
||||
this.baseUrl = process.env.REACT_APP_API_URL || process.env.REACT_APP_BACKEND_URL || '';
|
||||
const getApiBaseUrl = () => {
|
||||
const url = process.env.REACT_APP_API_URL;
|
||||
if (process.env.NODE_ENV === 'production' && !url) {
|
||||
throw new Error('REACT_APP_API_URL environment variable is required for production');
|
||||
}
|
||||
return url || 'http://localhost:8000';
|
||||
};
|
||||
this.baseUrl = getApiBaseUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,8 +12,16 @@ import {
|
||||
CopilotSuggestion
|
||||
} from '../types/seoCopilotTypes';
|
||||
|
||||
// Consistent API URL pattern - use same env vars as other services
|
||||
const API_BASE_URL = process.env.REACT_APP_API_URL || process.env.REACT_APP_BACKEND_URL || '';
|
||||
// API URL - require REACT_APP_API_URL in production
|
||||
const getApiBaseUrl = () => {
|
||||
const url = process.env.REACT_APP_API_URL;
|
||||
if (process.env.NODE_ENV === 'production' && !url) {
|
||||
throw new Error('REACT_APP_API_URL environment variable is required for production');
|
||||
}
|
||||
return url || 'http://localhost:8000';
|
||||
};
|
||||
|
||||
const API_BASE_URL = getApiBaseUrl();
|
||||
|
||||
class SEOApiService {
|
||||
private baseUrl: string;
|
||||
|
||||
@@ -21,8 +21,14 @@ export interface WASuggestResponse {
|
||||
class WritingAssistantService {
|
||||
private baseUrl: string;
|
||||
constructor() {
|
||||
// Consistent API URL pattern - no hardcoded localhost fallback
|
||||
this.baseUrl = process.env.REACT_APP_API_URL || process.env.REACT_APP_BACKEND_URL || '';
|
||||
const getApiBaseUrl = () => {
|
||||
const url = process.env.REACT_APP_API_URL;
|
||||
if (process.env.NODE_ENV === 'production' && !url) {
|
||||
throw new Error('REACT_APP_API_URL environment variable is required for production');
|
||||
}
|
||||
return url || 'http://localhost:8000';
|
||||
};
|
||||
this.baseUrl = getApiBaseUrl();
|
||||
}
|
||||
|
||||
async suggest(text: string): Promise<WASuggestion[]> {
|
||||
|
||||
Reference in New Issue
Block a user