import type { NextConfig } from "next";
import path from "node:path";

const nextConfig: NextConfig = {
  output: "standalone",
  outputFileTracingRoot: path.join(__dirname, "../.."),
  poweredByHeader: false,
  // In production Caddy routes /api/* to the API container (and blocks /api/internal/*).
  // In local dev there's no Caddy, so Next proxies it.
  async rewrites() {
    if (process.env.NODE_ENV === "production") return [];
    const api = process.env.API_INTERNAL_URL ?? "http://localhost:4000";
    return [{ source: "/api/:path((?!internal).*)", destination: `${api}/:path` }];
  },
};

export default nextConfig;
