In the docs for caching, the following example is given. Why is just a return
statement being used and what is being returned? I understand the return ends the function execution at that point where it’s used, but wouldn’t it be better to use something like
if (!cacheTag)
return new Response({ status: 401 })
I don’t know what is even being returned since the serverless function execution is essentially being switched off.
// purge a cache tag passed by query parameter
// applies to a specific Deploy Preview of a specific subdomain
import { purgeCache } from "@netlify/functions";
export default async (req: Request) => {
const url = new URL(req.url);
const cacheTag = url.searchParams.get("tag");
if (!cacheTag) {
return;
// ^^^^^^ why is a status not being returned as well?
}
const deployAlias = "deploy-preview-11";
const domain = "early-access.company.com";
console.log("Purging tag: ", cacheTag);
await purgeCache({
tags: [cacheTag],
deployAlias,
domain,
});
return new Response("Purged!", { status: 202 })
};