revalidate-headers.js 906 B

123456789101112131415161718192021
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.setRevalidateHeaders = setRevalidateHeaders;
  6. function setRevalidateHeaders(res, options) {
  7. if (options.private || options.stateful) {
  8. if (options.private || !res.hasHeader("Cache-Control")) {
  9. res.setHeader("Cache-Control", `private, no-cache, no-store, max-age=0, must-revalidate`);
  10. }
  11. } else if (typeof options.revalidate === "number") {
  12. if (options.revalidate < 1) {
  13. throw new Error(`invariant: invalid Cache-Control duration provided: ${options.revalidate} < 1`);
  14. }
  15. res.setHeader("Cache-Control", `s-maxage=${options.revalidate}, stale-while-revalidate`);
  16. } else if (options.revalidate === false) {
  17. res.setHeader("Cache-Control", `s-maxage=31536000, stale-while-revalidate`);
  18. }
  19. }
  20. //# sourceMappingURL=revalidate-headers.js.map