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

@@ -24,10 +24,23 @@ const baseConfig = {
],
},
async rewrites() {
const apiBaseUrl = process.env.API_BASE_URL || 'http://localhost:3001';
// Ensure API_BASE_URL is valid to prevent 500 errors
if (!apiBaseUrl || apiBaseUrl === 'undefined') {
console.warn('API_BASE_URL not set, using localhost fallback');
return [
{
source: '/api/:path*',
destination: 'http://localhost:3001/api/:path*',
},
];
}
return [
{
source: '/api/:path*',
destination: `${process.env.API_BASE_URL || 'http://localhost:3001'}/api/:path*`,
destination: `${apiBaseUrl}/api/:path*`,
},
];
},