/** @type {import('next').NextConfig} */
const nextConfig = {
  // Isolate dev and prod build output. `next start` (production) reads the
  // default `.next`; `next dev` is pointed at `.next-dev` via NEXT_DIST_DIR so a
  // stray dev run can never overwrite the live production manifests.
  distDir: process.env.NEXT_DIST_DIR || '.next',
  experimental: {
    serverComponentsExternalPackages: ['sharp'],
  },
  images: {
    remotePatterns: [
      { protocol: 'https', hostname: '**' },
    ],
  },
  async rewrites() {
    const rules = [
      { source: '/calendar.ics', destination: '/calendar' },
    ];
    if (process.env.NODE_ENV === 'development') {
      rules.push({
        source: '/api/:path*',
        destination: 'http://127.0.0.1:4000/api/:path*',
      });
    }
    return rules;
  },
};

module.exports = nextConfig;
