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; // Ensure API_BASE_URL is valid to prevent 500 errors if (!apiBaseUrl || apiBaseUrl === 'undefined') { console.warn('⚠️ API_BASE_URL not set! Set it to your backend domain'); console.warn('⚠️ Using localhost fallback - this will fail in production!'); return [ { source: '/api/:path*', destination: 'http://localhost:3001/api/:path*', }, ]; } console.log(`🔗 API rewrites pointing to: ${apiBaseUrl}`); 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;