/*
 * Copyright (c) 2026 Eliott Guillaumin
 * All rights reserved.
 */
import path from "node:path"
import { fileURLToPath } from "node:url"

/** @type {import('next').NextConfig} */
const projectRoot = path.dirname(fileURLToPath(import.meta.url))

const ultiProxyOrigin = process.env.ULTI_PROXY_ORIGIN ?? "http://127.0.0.1"

const nextConfig = {
  output: "standalone",
  // Docker standalone tracing only — do not set turbopack.root to projectRoot:
  // breaks Tailwind @import resolution (resolves from parent /Users/red/workdev).
  outputFileTracingRoot: projectRoot,
  allowedDevOrigins: ['192.168.0.20', '127.0.0.1', 'localhost', '100.120.4.66'],
  async rewrites() {
    return [
      {
        source: "/api/v1/:path*",
        destination: `${ultiProxyOrigin}/api/v1/:path*`,
      },
      {
        source: "/ai/:path*",
        destination: `${ultiProxyOrigin}/ai/:path*`,
      },
      {
        source: "/ai",
        destination: `${ultiProxyOrigin}/ai`,
      },
    ]
  },
  typescript: {
    ignoreBuildErrors: true,
  },
  images: {
    unoptimized: true,
  },
  turbopack: {
    resolveAlias: {
      canvas: "./lib/empty-module.mjs",
    },
  },
  webpack: (config) => {
    config.resolve.alias = {
      ...config.resolve.alias,
      canvas: false,
    }
    return config
  },
}

export default nextConfig
