Skip to content

Commit

Permalink
Merge pull request #221 from sametcodes/develop
Browse files Browse the repository at this point in the history
feat(#180): puts custom header for cache control
  • Loading branch information
sametcodes authored Oct 5, 2023
2 parents b4a398c + 252d730 commit bae2dcb
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;

2 comments on commit bae2dcb

@vercel
Copy link

@vercel vercel bot commented on bae2dcb Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

dsvgui – ./lib/@dsvgui

dsvgui-git-main-sametcodes.vercel.app
dsvgui.readme.rocks
dsvgui-sametcodes.vercel.app

@vercel
Copy link

@vercel vercel bot commented on bae2dcb Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

readmerocks – ./

readmerocks-sametcodes.vercel.app
readmerocks-git-main-sametcodes.vercel.app
readme.rocks
www.readme.rocks

Please sign in to comment.