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:
NotII
2025-09-01 16:31:12 +01:00
parent 29ec1be68c
commit 57c2fbdf50
5 changed files with 109 additions and 2 deletions

View File

@@ -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('/')