@scayle/storefront-nuxt
Version:
Nuxt integration for the SCAYLE Commerce Engine and Storefront API
30 lines (29 loc) • 1.02 kB
JavaScript
import { defineEventHandler, setResponseStatus } from "h3";
import { HttpStatusCode } from "@scayle/storefront-core";
import { eventHandlerWithCacheAuth } from "./cacheAuth.js";
export default eventHandlerWithCacheAuth(
defineEventHandler(async (event) => {
if (!event.context.$rpcContext) {
return new Response("No $rpcContext was found for the request", {
status: HttpStatusCode.INTERNAL_SERVER_ERROR
});
}
if (!event.context.$cache) {
return new Response("No $cache was found for the request", {
status: HttpStatusCode.INTERNAL_SERVER_ERROR
});
}
const logger = event.context.$rpcContext.log.space("purge-all");
try {
logger.debug("purging cache");
await event.context.$cache.purgeAll();
} catch (e) {
setResponseStatus(event, HttpStatusCode.INTERNAL_SERVER_ERROR);
if (typeof e === "string" || e instanceof Error) {
logger.error(e);
}
return { success: false };
}
return { success: true };
})
);