mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:36:30 +00:00
Optimize Next.js memory and handle 404s
Configure startup and package-import optimizations, exclude generated Next.js files from TypeScript checks, and route fetch responses with status 404 to the not-found page.
This commit is contained in:
+3
-1
@@ -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}`);
|
||||
}
|
||||
|
||||
@@ -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'],
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
+2
-2
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -30,5 +30,5 @@
|
||||
".next/dev/types/**/*.ts",
|
||||
"**/*.mts"
|
||||
],
|
||||
"exclude": ["node_modules", "**/*.old.tsx", "**/*.old.ts"]
|
||||
"exclude": ["node_modules", ".next", "**/*.old.tsx", "**/*.old.ts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user