import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  output: 'standalone',
  serverExternalPackages: ['busboy'],
  experimental: {
    middlewareClientMaxBodySize: '500mb',
  },
  async headers() {
    return [
      {
        source: '/(.*)',
        headers: [
          { key: 'X-Frame-Options', value: 'SAMEORIGIN' },
          { key: 'X-Content-Type-Options', value: 'nosniff' },
          { key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
          { key: 'Permissions-Policy', value: 'camera=(), microphone=(), geolocation=()' },
        ],
      },
    ];
  },
  async rewrites() {
    const martinUrl = process.env.MARTIN_URL || 'http://martin:3000';
    return [
      {
        source: '/tiles/:path*',
        destination: `${martinUrl}/:path*`,
      },
    ];
  },
};

export default nextConfig;
