This project demos latest next application with redis caching-layer.
More info:
- https://nextjs.org/docs/app/guides/self-hosting
- https://github.com/fortedigital/nextjs-cache-handler
- middleware rewrite not cached - vercel/next.js#83358
- nodejs v18 or higher
- docker (only required for
npm startcommand)
npm run dev- Start development server with mock APInpm run build- Build the application for productionnpm run start- Build and Start production server using Docker Composenpm run lint- Run ESLint to check code qualitynpm run typecheck- Run TypeScript type checkingnpm run api-mocks- Start mock API server
/- Home page with Next.js welcome content/count/[keyword]- Dynamic route that fetches count data for a given keyword (revalidates every 500 seconds)/lpvs/[lpv]/verticals/best/search/[keyword]- Nested dynamic route for search functionality (revalidates every 120 seconds)- Note: Only works when
lpvparameter equals "10000"
- Note: Only works when
POST /api/revalidate/path?path=<path>- Revalidates a specific path in the cache (currently not working)POST /api/revalidate/tag?tag=<tag>- Revalidates pages and api-requests caches- for example
POST /api/revalidate/tag?tag=10000:best:search:tv- revalidates lpv 10000 best vertical search/tv page
- for example
This application uses two types of URL rewrites to provide clean, SEO-friendly URLs while maintaining the underlying route structure:
Configured in next.config.ts:
/foo/:path*→/lpvs/10000/verticals/best/search/:path*- Example:
/foo/tv→/lpvs/10000/verticals/best/search/tv - This rewrite works well with caching (uses the internal route cache)
- Example:
Configured in middleware.ts:
/search/:path*→/lpvs/10000/verticals/best/search/:path*- Example:
/search/tv→/lpvs/10000/verticals/best/search/tv - This rewrite works well with caching (uses the internal route cache)
- Example:
You can test the rewrite functionality by visiting:
http://localhost:3000/search/tv(middleware rewrite) - cache workshttp://localhost:3000/foo/tv(config rewrite) - cache works
Revalidate path does not work