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:
@@ -31,7 +31,15 @@ export async function GET(req: NextRequest) {
|
||||
console.log('Auth check: Token found -', token.substring(0, 15) + '...');
|
||||
|
||||
const apiUrl = process.env.SERVER_API_URL || 'http://localhost:3001/api';
|
||||
console.log(`Auth check: Calling external API: ${apiUrl}/auth/me`);
|
||||
|
||||
// Validate API URL to prevent 500 errors
|
||||
if (!apiUrl || apiUrl === 'undefined' || apiUrl === 'null') {
|
||||
console.warn('SERVER_API_URL not properly set in auth check, using localhost fallback');
|
||||
const fallbackUrl = 'http://localhost:3001/api';
|
||||
console.log(`Auth check: Calling external API: ${fallbackUrl}/auth/me`);
|
||||
} else {
|
||||
console.log(`Auth check: Calling external API: ${apiUrl}/auth/me`);
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(`${apiUrl}/auth/me`, {
|
||||
|
||||
Reference in New Issue
Block a user