From 88ead4626cc9d6b89d24f2beb81a3ac4f9a6f9af Mon Sep 17 00:00:00 2001 From: soruly Date: Sun, 9 Aug 2020 15:21:46 +0800 Subject: Cache responses in edge server --- api/image-proxy.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/image-proxy.ts b/api/image-proxy.ts index 3bd88c8..334056d 100644 --- a/api/image-proxy.ts +++ b/api/image-proxy.ts @@ -28,6 +28,7 @@ export default async (request: NowRequest, response: NowResponse) => { if (["image", "video"].includes(res.headers.get("Content-Type").split("/")[0].toLowerCase())) { response.setHeader("Content-Type", res.headers.get("Content-Type")); + response.setHeader("Cache-Control", "s-maxage=86400"); } else if (res.headers.get("Content-Type").toLowerCase() === "application/octet-stream") { const match = imageURL.match(/\.(\w{3,4})($|\?)/); if (!match) return response.status(400).send("Error: Cannot determine Content-Type"); @@ -45,6 +46,7 @@ export default async (request: NowRequest, response: NowResponse) => { }[match[1]]; if (!contentType) return response.status(400).send("Error: Unknown Content-Type"); response.setHeader("Content-Type", contentType); + response.setHeader("Cache-Control", "s-maxage=86400"); } else { return response.status(400).send("Error: Unsupported Content-Type"); } -- cgit v1.2.3