# ── Falah Mobile on Netlify ─────────────────────────────────────
# Uses @netlify/plugin-nextjs for full Next.js serverless support

[build]
  command = "npm run build"
  publish = ".next"

[build.environment]
  NODE_VERSION = "20"

# Root redirect to /mobile (app has basePath: "/mobile")
[[redirects]]
  from = "/"
  to = "/mobile"
  status = 301

# OAuth callback: Casdoor redirects here without /mobile prefix
# Rewrite (200) so the auth callback route at /mobile/auth/callback handles it
[[redirects]]
  from = "/auth/callback"
  to = "/mobile/auth/callback"
  status = 200

# API routes need basePath prefix rewrite
[[redirects]]
  from = "/api/*"
  to = "/mobile/api/:splat"
  status = 200

# Everything else handled by Next.js plugin
[[redirects]]
  from = "/**"
  to = "/.netlify/functions/next_handler"
  status = 200

# Assets cache
[[headers]]
  for = "/mobile/_next/static/*"
  [headers.values]
    Cache-Control = "public, max-age=31536000, immutable"

# Prisma engine binary needed at runtime
[functions]
  included_files = ["node_modules/.prisma/**", "node_modules/@prisma/**"]
  node_bundler = "esbuild"