Add cache to files page

This commit is contained in:
Lee 2022-11-17 08:00:45 +00:00
parent 1369af0484
commit 4d728ed349
No known key found for this signature in database
GPG Key ID: 6EA25896ECCB3121

@ -14,7 +14,6 @@ export default function File({ isValidFile, fileData }) {
fileId, fileId,
originalFileName, originalFileName,
uploadDate, uploadDate,
contentType,
fileUrl, fileUrl,
width, width,
height, height,
@ -141,9 +140,13 @@ export default function File({ isValidFile, fileData }) {
); );
} }
export async function getServerSideProps(ctx) { export async function getServerSideProps({ query, res }) {
let { fileId } = ctx.query; let { fileId } = query;
fileId = fileId.split(".")[0]; fileId = fileId.split(".")[0];
res.setHeader(
"Cache-Control",
"public, s-maxage=10, stale-while-revalidate=300" // Cache for 5 minutes
);
const file = await getFileInfo(fileId); const file = await getFileInfo(fileId);
return { return {