diff --git a/lib/fetchData.ts b/lib/fetchData.ts index 924908e..1eb2cf1 100644 --- a/lib/fetchData.ts +++ b/lib/fetchData.ts @@ -1,4 +1,4 @@ -import { redirect } from "next/navigation" +import { notFound, redirect } from "next/navigation" import { ResponseData } from "@/types/types" import { logger } from "./logger" import { getCacheServerSession } from "./get-access-data" @@ -24,6 +24,7 @@ export default async function fetchData(url: string = '/', cache: "default" | "f console.log("FETCH ERROR DATA :", res.status, data) if (res.status === 401 || res.status === 403) return redirect(`/auth?error=Session error or has expired !`) + if (res.status === 404) notFound() // This will activate the closest `error.js` Error Boundary throw new Error(`(${data.code || res.status}) ${data.message || res.statusText}`) } @@ -62,6 +63,7 @@ export async function fetchDataWithPost(url: string = '/', payload: any = {}, ca console.log("FETCH ERROR DATA :", res.status, data) if (res.status === 401 || res.status === 403) redirect(`/auth?error=Session error or has expired !`); + if (res.status === 404) notFound() throw new Error(`(${data?.code || res.status} ${res.statusText}) ${data?.message}`); } diff --git a/next.config.ts b/next.config.ts index 5ee0e26..a12bea8 100644 --- a/next.config.ts +++ b/next.config.ts @@ -27,6 +27,11 @@ const nextConfig: NextConfig = { reactStrictMode: false, experimental: { authInterrupts: true, // for forbidden page + // MEMORY OPTIMIZING + // 1. Prevent Next.js from loading all route modules into RAM at startup + preloadEntriesOnStart: false, + // 2. Optimize barrel imports (e.g., lucide-react, @mui/icons-material, lodash) + optimizePackageImports: ['lucide-react', 'date-fns', 'lodash'], }, }; diff --git a/package.json b/package.json index 2874871..bdfa089 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "url": "https://github.com/ichsankurnia/hats-app/issues" }, "scripts": { - "dev": "next dev -p 1209", + "dev": "set NODE_OPTIONS=\"--max-old-space-size=2048\" && next dev -p 1209", "dev:save": "set NODE_TLS_REJECT_UNAUTHORIZED='0' && next dev -p 1209", "build": "next build", "start": "next start -p 7002", @@ -95,4 +95,4 @@ "tw-animate-css": "^1.4.0", "typescript": "^5" } -} +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 7ca0f21..3b9ba33 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -30,5 +30,5 @@ ".next/dev/types/**/*.ts", "**/*.mts" ], - "exclude": ["node_modules", "**/*.old.tsx", "**/*.old.ts"] + "exclude": ["node_modules", ".next", "**/*.old.tsx", "**/*.old.ts"] }