import type { NextConfig } from "next"; import { withSentryConfig } from "@sentry/nextjs"; // Requests for the backend (/api, /uploads) that reach the site anyway are passed to it (3.6.1). // On a server nginx sends those paths to the backend, but a proxy in front can send some to the // site instead: one with a rule for file extensions (static-file caching) sent every // /api/uploads/…png here, so an uploaded logo never showed. BACKEND_INTERNAL_URL is the backend on // this server (http://127.0.0.1:), never the public address, which would come straight back // here. The end-to-end tests set E2E_API_PROXY (3.0.0): the site and its API on one address, as // nginx does, so Accounts' sign-in comes back to /api/auth/callback. const backend = (process.env.BACKEND_INTERNAL_URL || process.env.E2E_API_PROXY || "").replace(/\/+$/, ""); const nextConfig: NextConfig = { // The end-to-end tests run their own dev server; a separate build folder keeps it // from clashing with one already running. distDir: process.env.NEXT_DIST_DIR || ".next", images: { // (images.domains is deprecated in Next 16.) remotePatterns: [{ protocol: 'https', hostname: 'images.unsplash.com' }], }, compiler: { removeConsole: process.env.NODE_ENV === 'production', }, ...(backend ? { // beforeFiles: ahead of every page, so a dynamic route like /[redirectUrl] never catches them. async rewrites() { return { beforeFiles: [ { source: '/api/:path*', destination: `${backend}/api/:path*` }, { source: '/uploads/:path*', destination: `${backend}/uploads/:path*` }, ], afterFiles: [], fallback: [], }; }, } : {}), }; // A no-op wrap when SENTRY_DSN isn't configured for this deployment — safe in // every environment (dev, or a fresh deploy that hasn't set up Sentry yet). export default process.env.NEXT_PUBLIC_SENTRY_DSN ? withSentryConfig(nextConfig, { silent: true, disableLogger: true }) : nextConfig;