0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Added JSDoc to cache control middleware

no-issue
This commit is contained in:
Fabien "egg" O'Carroll 2022-01-14 13:34:35 +02:00
parent 02e4aeccd9
commit 76b33b6e77

View file

@ -8,6 +8,11 @@
const isString = require('lodash/isString');
/**
* @param {'public'|'private'} profile Use "private" if you do not want caching
* @param {object} [options]
* @param {number} [options.maxAge] The max-age in seconds to use when profile is "public"
*/
const cacheControl = (profile, options = {maxAge: 0}) => {
const profiles = {
public: `public, max-age=${options.maxAge}`,
@ -20,6 +25,13 @@ const cacheControl = (profile, options = {maxAge: 0}) => {
output = profiles[profile];
}
/**
* @param {import('express').Request} req
* @param {import('express').Response} res
* @param {() => void} next
*
* @returns {void}
*/
return function cacheControlHeaders(req, res, next) {
if (output) {
res.set({'Cache-Control': output});