Files
ember-market-frontend/next.config.mjs
NotII 57c2fbdf50 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.
2025-09-01 16:31:12 +01:00

66 lines
1.6 KiB
JavaScript

import bundleAnalyzer from '@next/bundle-analyzer';
const withBundleAnalyzer = bundleAnalyzer({ enabled: process.env.ANALYZE === 'true' });
/** @type {import('next').NextConfig} */
const baseConfig = {
output: 'standalone',
reactStrictMode: false,
images: {
remotePatterns: [
{
protocol: "https",
hostname: "api.telegram.org",
},
{
protocol: "https",
hostname: "telegram.org",
},
// Backend API hostname configured via environment variable
...(process.env.API_HOSTNAME ? [{
protocol: "https",
hostname: process.env.API_HOSTNAME,
}] : []),
],
},
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: `${apiBaseUrl}/api/:path*`,
},
];
},
experimental: {
// serverExternalPackages has been deprecated in Next.js 15
},
onDemandEntries: {
maxInactiveAge: 15 * 1000,
pagesBufferLength: 2,
},
productionBrowserSourceMaps: false,
typescript: {
ignoreBuildErrors: true,
},
eslint: {
ignoreDuringBuilds: true,
},
};
const nextConfig = withBundleAnalyzer(baseConfig);
export default nextConfig;