Add CapRover deployment fix and improve env var handling
Added CAPROVER-DEPLOYMENT-FIX.md with instructions for required environment variables to prevent 500 errors. Improved validation and fallback logic for SERVER_API_URL and API_BASE_URL in server-api.ts, route.ts, and next.config.mjs to handle missing or invalid values gracefully and log warnings instead of crashing.
This commit is contained in:
@@ -22,6 +22,17 @@ try {
|
||||
*/
|
||||
function getServerApiUrl(endpoint: string): string {
|
||||
const apiUrl = process.env.SERVER_API_URL || 'http://localhost:3001/api';
|
||||
|
||||
// Validate API URL to prevent 500 errors
|
||||
if (!apiUrl || apiUrl === 'undefined' || apiUrl === 'null') {
|
||||
console.warn('SERVER_API_URL not properly set, using localhost fallback');
|
||||
const fallbackUrl = 'http://localhost:3001/api';
|
||||
const cleanEndpoint = endpoint.startsWith('/') ? endpoint.substring(1) : endpoint;
|
||||
return fallbackUrl.endsWith('/')
|
||||
? `${fallbackUrl}${cleanEndpoint}`
|
||||
: `${fallbackUrl}/${cleanEndpoint}`;
|
||||
}
|
||||
|
||||
const cleanEndpoint = endpoint.startsWith('/') ? endpoint.substring(1) : endpoint;
|
||||
|
||||
return apiUrl.endsWith('/')
|
||||
|
||||
Reference in New Issue
Block a user