diff --git a/middlewares/api/cache.ts b/middlewares/api/cache.ts index 3b554cb..6e47f0a 100644 --- a/middlewares/api/cache.ts +++ b/middlewares/api/cache.ts @@ -6,15 +6,14 @@ export const setCacheControl = ( next: () => void ) => { const { - query: { cache_time }, + query: { cache_time, _vercel_no_cache }, } = res.locals; - const cacheValue = `s-maxage=${ - cache_time || 60 - }, stale-while-revalidate=604800`; - res.setHeader("Cache-Control", cacheValue); - if (req.query._vercel_no_cache && req.query._vercel_no_cache === "1") { - res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate=59"); + res.setHeader("Cache-Control", "max-age=60"); + if (_vercel_no_cache === undefined) { + res.setHeader("CDN-Cache-Control", `max-age=${cache_time}`); + res.setHeader("Vercel-CDN-Cache-Control", `max-age=${cache_time}`); } + next(); }; diff --git a/next.config.js b/next.config.js index f40a0b9..365fa9c 100644 --- a/next.config.js +++ b/next.config.js @@ -28,28 +28,6 @@ const nextConfig = { }, ]; }, - async headers() { - return [ - { - source: "/api/view", - headers: [ - { - key: "Cache-Control", - value: "s-maxage=60, stale-while-revalidate=604800", - }, - ], - }, - { - source: "/api/view/:id*", - headers: [ - { - key: "Cache-Control", - value: "s-maxage=60, stale-while-revalidate=604800", - }, - ], - }, - ]; - }, }; module.exports = nextConfig;