2026-05-27 21:34:12 +03:30
|
|
|
import type { NextConfig } from "next";
|
|
|
|
|
import createNextIntlPlugin from "next-intl/plugin";
|
|
|
|
|
import withPWAInit from "@ducanh2912/next-pwa";
|
|
|
|
|
|
|
|
|
|
const withNextIntl = createNextIntlPlugin("./src/i18n/request.ts");
|
|
|
|
|
|
|
|
|
|
const withPWA = withPWAInit({
|
|
|
|
|
dest: "public",
|
|
|
|
|
cacheOnFrontEndNav: true,
|
|
|
|
|
aggressiveFrontEndNavCaching: true,
|
|
|
|
|
reloadOnOnline: true,
|
|
|
|
|
disable: process.env.NODE_ENV === "development",
|
|
|
|
|
workboxOptions: {
|
|
|
|
|
disableDevLogs: true,
|
2026-06-15 20:42:38 +03:30
|
|
|
// Pick up a new deploy promptly and never serve a stale shell that points
|
|
|
|
|
// at JS chunks the new build replaced (which looked like being logged out
|
|
|
|
|
// after every update).
|
|
|
|
|
skipWaiting: true,
|
|
|
|
|
clientsClaim: true,
|
|
|
|
|
cleanupOutdatedCaches: true,
|
2026-05-27 21:34:12 +03:30
|
|
|
runtimeCaching: [
|
2026-06-15 20:42:38 +03:30
|
|
|
// HTML navigations: always try the network first so the document and its
|
|
|
|
|
// chunk references match the currently-deployed build; fall back to cache
|
|
|
|
|
// only when offline.
|
|
|
|
|
{
|
|
|
|
|
urlPattern: ({ request }: { request: Request }) => request.mode === "navigate",
|
|
|
|
|
handler: "NetworkFirst",
|
|
|
|
|
options: {
|
|
|
|
|
cacheName: "pages",
|
|
|
|
|
networkTimeoutSeconds: 5,
|
|
|
|
|
expiration: { maxEntries: 50, maxAgeSeconds: 24 * 60 * 60 },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
// Hashed static chunks are immutable per build — cache-first is safe and fast.
|
2026-05-27 21:34:12 +03:30
|
|
|
{
|
|
|
|
|
urlPattern: /\/_next\/static\//,
|
|
|
|
|
handler: "CacheFirst",
|
|
|
|
|
options: {
|
|
|
|
|
cacheName: "static-assets",
|
|
|
|
|
expiration: { maxEntries: 200, maxAgeSeconds: 30 * 24 * 60 * 60 },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
// API: NetworkFirst — show cached data when offline
|
|
|
|
|
{
|
|
|
|
|
urlPattern: /\/api\//,
|
|
|
|
|
handler: "NetworkFirst",
|
|
|
|
|
options: {
|
|
|
|
|
cacheName: "api-data",
|
|
|
|
|
networkTimeoutSeconds: 5,
|
|
|
|
|
expiration: { maxEntries: 300, maxAgeSeconds: 10 * 60 },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
// Menu images & media
|
|
|
|
|
{
|
|
|
|
|
urlPattern: /\.(?:png|jpg|jpeg|svg|gif|webp|ico)$/,
|
|
|
|
|
handler: "StaleWhileRevalidate",
|
|
|
|
|
options: {
|
|
|
|
|
cacheName: "media-cache",
|
|
|
|
|
expiration: { maxEntries: 300, maxAgeSeconds: 7 * 24 * 60 * 60 },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const adminWebOrigin =
|
|
|
|
|
process.env.ADMIN_WEB_ORIGIN ?? "http://localhost:3102";
|
|
|
|
|
|
|
|
|
|
const nextConfig: NextConfig = {
|
|
|
|
|
output: "standalone",
|
|
|
|
|
experimental: {
|
|
|
|
|
optimizePackageImports: ["recharts", "lucide-react"],
|
|
|
|
|
},
|
|
|
|
|
async redirects() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
source: "/:locale(fa|ar|en)/admin",
|
|
|
|
|
destination: `${adminWebOrigin}/:locale/admin`,
|
|
|
|
|
permanent: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
source: "/:locale(fa|ar|en)/admin/:path*",
|
|
|
|
|
destination: `${adminWebOrigin}/:locale/admin/:path*`,
|
|
|
|
|
permanent: false,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default withPWA(withNextIntl(nextConfig));
|