import type { NextConfig } from "next";

/** Standalone is for Docker/VPS (`node server.js`). Vercel uses its own adapter. */
const useStandalone =
  process.env.DOCKER_BUILD === "1" || process.env.OUTPUT_STANDALONE === "1";

const nextConfig: NextConfig = {
  ...(useStandalone ? { output: "standalone" as const } : {}),
  experimental: {
    // Large ROM uploads via /api/contribute (multipart) — VPS/Docker only.
    // Defaults are ~1–10MB and will break PS1/N64/etc. uploads.
    serverActions: {
      bodySizeLimit: "512mb",
    },
    proxyClientMaxBodySize: "512mb",
  },
  async headers() {
    return [
      {
        source: "/roms/:path*",
        headers: [
          {
            key: "Cross-Origin-Resource-Policy",
            value: "cross-origin",
          },
          {
            key: "Cache-Control",
            value: "public, max-age=3600",
          },
        ],
      },
      {
        source: "/:path*",
        headers: [
          { key: "Cross-Origin-Opener-Policy", value: "same-origin" },
          { key: "Cross-Origin-Embedder-Policy", value: "credentialless" },
          { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
          { key: "X-Content-Type-Options", value: "nosniff" },
          {
            key: "Permissions-Policy",
            value: "camera=(), microphone=(), geolocation=()",
          },
        ],
      },
    ];
  },
};

export default nextConfig;
