From a9ff0e894761c624505c1110cd23480c5147353e Mon Sep 17 00:00:00 2001 From: Wini_Fy Date: Fri, 6 Feb 2026 12:09:33 +0700 Subject: [PATCH] fix: blog dynamic build --- api/aboutApi.ts | 4 ++-- api/blogsApi.ts | 28 +++++++++------------------- api/servicesApi.ts | 4 ++++ app/about/page.tsx | 3 +++ app/blog/[slug]/page.tsx | 3 +++ app/page.tsx | 3 +++ app/services/page.tsx | 3 +++ app/visa/page.tsx | 3 +++ 8 files changed, 30 insertions(+), 21 deletions(-) diff --git a/api/aboutApi.ts b/api/aboutApi.ts index 3de4d1c..d893c5e 100644 --- a/api/aboutApi.ts +++ b/api/aboutApi.ts @@ -15,10 +15,10 @@ export const aboutApi = { try { const apiUrl = getApiUrl(); const response = await fetch(`${apiUrl}/api/about`, { + // Không cache - luôn fetch dữ liệu mới nhất cache: 'no-store', headers: { - 'Cache-Control': 'no-cache', - 'Pragma': 'no-cache' + 'Content-Type': 'application/json', } }); if (!response.ok) { diff --git a/api/blogsApi.ts b/api/blogsApi.ts index 0f8b43a..54df225 100644 --- a/api/blogsApi.ts +++ b/api/blogsApi.ts @@ -53,9 +53,7 @@ export const fetchBlogList = async ( headers: { 'Content-Type': 'application/json', }, - // Next.js: cache và revalidate (disabled) - // next: { revalidate: 60 }, // Revalidate mỗi 60 giây - // no-cache + // Không cache - luôn fetch dữ liệu mới nhất cache: 'no-store', }); @@ -91,8 +89,7 @@ export const fetchBlogDetail = async ( headers: { 'Content-Type': 'application/json', }, - // No cache for blog detail (disabled caching) - // no-cache + // Không cache - luôn fetch dữ liệu mới nhất cache: 'no-store', }); @@ -131,8 +128,7 @@ export const fetchFeaturedBlogs = async ( headers: { 'Content-Type': 'application/json', }, - // next: { revalidate: 60 }, - // no-cache + // Không cache - luôn fetch dữ liệu mới nhất cache: 'no-store', }); @@ -168,8 +164,7 @@ export const fetchRecentBlogs = async ( headers: { 'Content-Type': 'application/json', }, - // next: { revalidate: 60 }, - // no-cache + // Không cache - luôn fetch dữ liệu mới nhất cache: 'no-store', }); @@ -202,8 +197,7 @@ export const fetchCategories = async (): Promise => { headers: { 'Content-Type': 'application/json', }, - // next: { revalidate: 300 }, // Categories ít thay đổi, cache lâu hơn - // no-cache + // Không cache - luôn fetch dữ liệu mới nhất cache: 'no-store', }); @@ -239,8 +233,7 @@ export const fetchCategoryDetail = async ( headers: { 'Content-Type': 'application/json', }, - // next: { revalidate: 300 }, - // no-cache + // Không cache - luôn fetch dữ liệu mới nhất cache: 'no-store', }); @@ -276,8 +269,7 @@ export const fetchTags = async (): Promise => { headers: { 'Content-Type': 'application/json', }, - // next: { revalidate: 300 }, - // no-cache + // Không cache - luôn fetch dữ liệu mới nhất cache: 'no-store', }); @@ -313,8 +305,7 @@ export const fetchPopularTags = async ( headers: { 'Content-Type': 'application/json', }, - // next: { revalidate: 300 }, - // no-cache + // Không cache - luôn fetch dữ liệu mới nhất cache: 'no-store', }); @@ -350,8 +341,7 @@ export const fetchTagDetail = async ( headers: { 'Content-Type': 'application/json', }, - // next: { revalidate: 300 }, - // no-cache + // Không cache - luôn fetch dữ liệu mới nhất cache: 'no-store', }); diff --git a/api/servicesApi.ts b/api/servicesApi.ts index 9bae705..5c1d230 100644 --- a/api/servicesApi.ts +++ b/api/servicesApi.ts @@ -138,6 +138,8 @@ export const fetchServicePageData = async (): Promise => { headers: { "Content-Type": "application/json", }, + // Không cache - luôn fetch dữ liệu mới nhất + cache: "no-store", }); console.log("Services API response status:", response.status); @@ -179,6 +181,8 @@ export const fetchServiceBySlug = async (slug: string): Promise => { headers: { "Content-Type": "application/json", }, + // Không cache - luôn fetch dữ liệu mới nhất + cache: "no-store", }); console.log("Response status:", response.status); diff --git a/app/about/page.tsx b/app/about/page.tsx index 8730cde..e8958c5 100644 --- a/app/about/page.tsx +++ b/app/about/page.tsx @@ -1,6 +1,9 @@ import { AboutHero, AboutIntro, AboutMission, AboutFeatures, AboutNews } from "../components/about"; import { aboutApi } from "../../api/aboutApi"; +// Force dynamic rendering - không cache +export const dynamic = 'force-dynamic'; + export default async function AboutPage() { const data = await aboutApi.getAbout(); diff --git a/app/blog/[slug]/page.tsx b/app/blog/[slug]/page.tsx index 10ea765..336f3ec 100644 --- a/app/blog/[slug]/page.tsx +++ b/app/blog/[slug]/page.tsx @@ -6,6 +6,9 @@ import { fetchBlogList, fetchBlogDetail } from "@/api/blogsApi"; import Sidebar from "@/app/blog/components/Sidebar"; import { getCmsImageUrl } from "@/utils"; +// Force dynamic rendering - không cache +export const dynamic = 'force-dynamic'; + // Generate static params for all blog posts export async function generateStaticParams() { try { diff --git a/app/page.tsx b/app/page.tsx index 10c1914..a7caf9f 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -12,6 +12,9 @@ import localHomeData from './home.json'; import { getCmsImageUrl } from '@/utils/image'; import { fetchHomeData } from '@/api'; +// Force dynamic rendering - không cache +export const dynamic = 'force-dynamic'; + export default async function Home() { // Fetch home data (blog aggregation is now handled by the backend) const apiHomeData = await fetchHomeData(); diff --git a/app/services/page.tsx b/app/services/page.tsx index 5147e09..5962b99 100644 --- a/app/services/page.tsx +++ b/app/services/page.tsx @@ -4,6 +4,9 @@ import Breadcrumb from "../components/Breadcrumb"; import ImageWithFallback from "../components/ImageWithFallback"; import "./services.css"; +// Force dynamic rendering - không cache +export const dynamic = 'force-dynamic'; + export default async function ServicesPage() { const data = await fetchServicePageData(); const allCountries = await fetchCountries(); diff --git a/app/visa/page.tsx b/app/visa/page.tsx index 02c4c6d..f5401a9 100644 --- a/app/visa/page.tsx +++ b/app/visa/page.tsx @@ -3,6 +3,9 @@ import Breadcrumb from "../components/Breadcrumb"; import { fetchVisaData, type VisaCountry } from "@/api/visa"; +// Force dynamic rendering - không cache +export const dynamic = 'force-dynamic'; + export default async function VisaListPage() { // Fetch all visa countries từ API let visaCountries: any[] = [];