const basePath = process.env.NEXT_BASE_PATH || "";
const backendHost = process.env.BACKEND_HOST || "127.0.0.1";
const backendPort = process.env.BACKEND_PORT || "8000";
const apiUpstream = process.env.INTERNAL_API_UPSTREAM || `http://${backendHost}:${backendPort}`;
const adminApiUpstream = process.env.INTERNAL_ADMIN_API_UPSTREAM || "http://127.0.0.1:8001";
const distDir = process.env.NEXT_DIST_DIR || ".next";
const assetPrefix = process.env.NEXT_ASSET_PREFIX || "";

/** @type {import('next').NextConfig} */
const nextConfig = {
  basePath,
  assetPrefix,
  distDir,
  devIndicators: false,
  experimental: {
    middlewareClientMaxBodySize: "80mb"
  },
  async rewrites() {
    return [
      {
        source: "/api/admin/:path*",
        destination: `${adminApiUpstream}/:path*`,
        basePath: false
      },
      {
        source: "/api/:path*",
        destination: `${apiUpstream}/:path*`,
        basePath: false
      }
    ];
  }
};

export default nextConfig;
