Skip to content

Commit 252d730

Browse files
authored
Merge pull request #220 from sametcodes/180-504-gateway-timeout-on-view-api-1
feat(#180): puts custom header for cache control
2 parents b4a398c + 1906122 commit 252d730

File tree

2 files changed

+6
-29
lines changed

2 files changed

+6
-29
lines changed

middlewares/api/cache.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ export const setCacheControl = (
66
next: () => void
77
) => {
88
const {
9-
query: { cache_time },
9+
query: { cache_time, _vercel_no_cache },
1010
} = res.locals;
11-
const cacheValue = `s-maxage=${
12-
cache_time || 60
13-
}, stale-while-revalidate=604800`;
14-
res.setHeader("Cache-Control", cacheValue);
1511

16-
if (req.query._vercel_no_cache && req.query._vercel_no_cache === "1") {
17-
res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate=59");
12+
res.setHeader("Cache-Control", "max-age=60");
13+
if (_vercel_no_cache === undefined) {
14+
res.setHeader("CDN-Cache-Control", `max-age=${cache_time}`);
15+
res.setHeader("Vercel-CDN-Cache-Control", `max-age=${cache_time}`);
1816
}
17+
1918
next();
2019
};

next.config.js

-22
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,6 @@ const nextConfig = {
2828
},
2929
];
3030
},
31-
async headers() {
32-
return [
33-
{
34-
source: "/api/view",
35-
headers: [
36-
{
37-
key: "Cache-Control",
38-
value: "s-maxage=60, stale-while-revalidate=604800",
39-
},
40-
],
41-
},
42-
{
43-
source: "/api/view/:id*",
44-
headers: [
45-
{
46-
key: "Cache-Control",
47-
value: "s-maxage=60, stale-while-revalidate=604800",
48-
},
49-
],
50-
},
51-
];
52-
},
5331
};
5432

5533
module.exports = nextConfig;

0 commit comments

Comments
 (0)