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:
@@ -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*`,
|
||||
},
|
||||
];
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user