import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  /* config options here */
  allowedDevOrigins: ['192.168.1.25', 'localhost', 'localhost:3000', '127.0.0.1'],
  async rewrites() {
    // Proxy any /api/* calls from the browser to the backend service.
    // In Docker compose the backend service is reachable at http://backend:3001.
    // This keeps requests same-origin (no mixed-content) and avoids CORS/mixed-protocol issues.
    return [
      {
        source: '/api/:path*',
        destination: process.env.NEXT_PUBLIC_API_URL
          ? process.env.NEXT_PUBLIC_API_URL.replace(/^https?:/, 'http:') + '/api/:path*'
          : 'http://backend:3001/api/:path*',
      },
    ];
  },
};

export default nextConfig;
