Skip to content

Commit f8a82d5

Browse files
fix: Default backend to topicsflow.me and remove BACKEND_IP usage
- Remove usage of BACKEND_IP env var from frontend/utils/api.ts and frontend/next.config.js. - Default API base URL to https://topicsflow.me if NEXT_PUBLIC_API_URL is not set. - Ensure localhost:5000 is not used as a fallback on Azure/Production. - Only use NEXT_PUBLIC_API_URL for configuration.
1 parent 7120a03 commit f8a82d5

2 files changed

Lines changed: 21 additions & 23 deletions

File tree

frontend/next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ if (!isExport) {
102102
// In local development, frontend connects directly to localhost:5000 (no proxy needed)
103103
// Only enable proxy for Azure production where we need to redirect /api/* to backend
104104
const isProduction = process.env.NODE_ENV === 'production';
105-
const backendUrl = process.env.NEXT_PUBLIC_API_URL || process.env.BACKEND_IP;
105+
const backendUrl = process.env.NEXT_PUBLIC_API_URL;
106106

107107
if (isProduction && backendUrl) {
108108
// Azure production: Proxy /api/* to backend URL

frontend/utils/api.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ class ApiClient {
88
constructor() {
99
// IMPORTANT:
1010
// In browser:
11-
// - Production (Azure): Use `api.topicsflow.me` directly for CORS compatibility
11+
// - Production (Azure): Use `topicsflow.me` directly
1212
// - Local Development: Use `http://localhost:5000` directly (bypass Next.js proxy)
1313
//
14-
// On the server (SSR/scripts), use BACKEND_IP or NEXT_PUBLIC_API_URL for absolute calls.
15-
const backendUrl = process.env.BACKEND_IP || process.env.NEXT_PUBLIC_API_URL;
14+
// On the server (SSR/scripts), use NEXT_PUBLIC_API_URL for absolute calls.
15+
const backendUrl = process.env.NEXT_PUBLIC_API_URL;
1616
let baseURL: string;
1717

1818
if (typeof window !== 'undefined') {
@@ -21,21 +21,22 @@ class ApiClient {
2121
window.location.hostname === 'www.topicsflow.me' ||
2222
window.location.hostname.includes('azurestaticapps.net');
2323

24-
if (isProduction && backendUrl) {
25-
// Production (Azure): Use provided backend URL
24+
if (backendUrl) {
25+
// Use provided backend URL
2626
baseURL = backendUrl;
2727
} else if (isProduction) {
28-
// Production but no backend URL set: use relative paths (same domain)
28+
// Production but no backend URL set: use topicsflow.me
2929
// This allows calls to go to /api/... on the same domain (topicsflow.me)
30-
baseURL = '';
30+
baseURL = 'https://topicsflow.me';
3131
} else {
32-
// Local Development: Always use localhost:5000 directly (no proxy)
33-
// This ensures direct connection to backend for better debugging
34-
baseURL = backendUrl || 'http://localhost:5000';
32+
// Local Development: Use provided URL or default to topicsflow.me if not set
33+
// (to avoid accidental localhost usage when targeting prod)
34+
// However, if needed for local dev without env var, users should set NEXT_PUBLIC_API_URL
35+
baseURL = backendUrl || 'https://topicsflow.me';
3536
}
3637
} else {
3738
// Server-side: use environment variable
38-
baseURL = backendUrl || 'http://localhost:5000';
39+
baseURL = backendUrl || 'https://topicsflow.me';
3940
}
4041

4142
this.client = axios.create({
@@ -527,27 +528,24 @@ export const clearCache = (pattern?: string) => {
527528
export const getApiBaseUrl = (): string => {
528529
if (typeof window === 'undefined') {
529530
// Server-side: use environment variable
530-
return process.env.BACKEND_IP || process.env.NEXT_PUBLIC_API_URL || 'http://localhost:5000';
531+
return process.env.NEXT_PUBLIC_API_URL || 'https://topicsflow.me';
531532
}
532533

533534
// Browser: Check if we're in production (Azure)
534535
const isProduction = window.location.hostname === 'topicsflow.me' ||
535536
window.location.hostname === 'www.topicsflow.me' ||
536537
window.location.hostname.includes('azurestaticapps.net');
537538

538-
const backendUrl = process.env.BACKEND_IP || process.env.NEXT_PUBLIC_API_URL;
539+
const backendUrl = process.env.NEXT_PUBLIC_API_URL;
539540

540-
if (isProduction && backendUrl) {
541-
// Production: Use backend URL directly
541+
if (backendUrl) {
542+
// Use backend URL directly
542543
return backendUrl;
543544
} else if (isProduction) {
544-
// Production but no backend URL set: use current origin
545-
if (typeof window !== 'undefined') {
546-
return window.location.origin;
547-
}
548-
return '';
545+
// Production but no backend URL set: use topicsflow.me
546+
return 'https://topicsflow.me';
549547
} else {
550-
// Local Development: Always use localhost:5000 directly (no proxy)
551-
return backendUrl || 'http://localhost:5000';
548+
// Local Development:
549+
return backendUrl || 'https://topicsflow.me';
552550
}
553551
};

0 commit comments

Comments
 (0)