Skip to content

Commit

Permalink
Merge pull request #220 from sametcodes/180-504-gateway-timeout-on-vi…
Browse files Browse the repository at this point in the history
…ew-api-1

feat(#180): puts custom header for cache control
  • Loading branch information
sametcodes authored Oct 5, 2023
2 parents b4a398c + 1906122 commit 252d730
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
13 changes: 6 additions & 7 deletions middlewares/api/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
22 changes: 0 additions & 22 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 252d730

Please sign in to comment.