/** @type {import('next').NextConfig} */ const BACKEND_INTERNAL_URL = process.env.BACKEND_INTERNAL_URL || "http://localhost:20001"; const nextConfig = { reactStrictMode: true, output: "standalone", images: { remotePatterns: [{ protocol: "http", hostname: "**" }, { protocol: "https", hostname: "**" }] }, async headers() { return [ { /* sw.js และ version.json ต้องไม่ถูก HTTP cache — ไม่งั้นผู้ใช้ค้างรุ่นเก่า */ source: "/sw.js", headers: [ { key: "Cache-Control", value: "no-cache, no-store, must-revalidate" }, { key: "Service-Worker-Allowed", value: "/" }, ], }, { source: "/version.json", headers: [{ key: "Cache-Control", value: "no-cache, no-store, must-revalidate" }], }, { source: "/ui-manifest.json", headers: [{ key: "Cache-Control", value: "public, max-age=0, must-revalidate" }], }, { /* หน้าเว็บ (HTML) เป็น static prerender → Next แปะ s-maxage=31536000 (1 ปี) ทำให้เบราว์เซอร์ค้างหน้าเก่าหลัง deploy ใหม่ จึงบังคับ no-store เฉพาะ text/html (ไม่กระทบ _next/static ที่มี hash อยู่แล้ว) */ source: "/:path*", has: [{ type: "header", key: "accept", value: "(.*text/html.*)" }], headers: [ { key: "Cache-Control", value: "private, no-cache, no-store, max-age=0, must-revalidate" }, ], }, ]; }, async rewrites() { return [ { source: "/api/:path*", destination: `${BACKEND_INTERNAL_URL}/api/:path*` } ]; } }; export default nextConfig;