diff --git a/config/api.config.js b/config/api.config.js index 22c3345..3b2f238 100644 --- a/config/api.config.js +++ b/config/api.config.js @@ -28,4 +28,8 @@ module.exports = { // The directLinkRegex is used to match the direct link of the file from the response of the API. We originally use this to prevent // unauthorised use of the proxied download feature - but that is disabled for now. So you can safely ignore this settings. directLinkRegex: 'public[.].*[.]files[.]1drv[.]com', + + // Cache-Control header, check Vercel documentation for more details. + // https://vercel.com/docs/concepts/edge-network/caching + cacheControlHeader: 'max-age=0, s-maxage=1, stale-while-revalidate=59' } diff --git a/pages/api/index.ts b/pages/api/index.ts index 4f13f63..752bec5 100644 --- a/pages/api/index.ts +++ b/pages/api/index.ts @@ -133,7 +133,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) // Set edge function caching for faster load times, check docs: // https://vercel.com/docs/concepts/functions/edge-caching - res.setHeader('Cache-Control', 'max-age=0, s-maxage=600, stale-while-revalidate') + res.setHeader('Cache-Control', apiConfig.cacheControlHeader) // Sometimes the path parameter is defaulted to '[...path]' which we need to handle if (path === '[...path]') { diff --git a/pages/api/item.ts b/pages/api/item.ts index 322c32e..7884105 100644 --- a/pages/api/item.ts +++ b/pages/api/item.ts @@ -13,7 +13,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) // Set edge function caching for faster load times, check docs: // https://vercel.com/docs/concepts/functions/edge-caching - res.setHeader('Cache-Control', 'max-age=0, s-maxage=600, stale-while-revalidate') + res.setHeader('Cache-Control', apiConfig.cacheControlHeader) if (typeof id === 'string') { const itemApi = `${apiConfig.driveApi}/items/${id}` diff --git a/pages/api/search.ts b/pages/api/search.ts index 40abfff..7f07c21 100644 --- a/pages/api/search.ts +++ b/pages/api/search.ts @@ -34,7 +34,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) // Set edge function caching for faster load times, check docs: // https://vercel.com/docs/concepts/functions/edge-caching - res.setHeader('Cache-Control', 'max-age=0, s-maxage=600, stale-while-revalidate') + res.setHeader('Cache-Control', apiConfig.cacheControlHeader) if (typeof searchQuery === 'string') { // Construct Microsoft Graph Search API URL, and perform search only under the base directory diff --git a/pages/api/thumbnail.ts b/pages/api/thumbnail.ts index 652ff21..48fd84c 100644 --- a/pages/api/thumbnail.ts +++ b/pages/api/thumbnail.ts @@ -17,7 +17,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) // Set edge function caching for faster load times, check docs: // https://vercel.com/docs/concepts/functions/edge-caching - res.setHeader('Cache-Control', 'max-age=0, s-maxage=600, stale-while-revalidate') + res.setHeader('Cache-Control', apiConfig.cacheControlHeader) // Check whether the size is valid - must be one of 'large', 'medium', or 'small' if (size !== 'large' && size !== 'medium' && size !== 'small') {