@@ -9,13 +9,16 @@ import versionSatisfiesRange from '../lib/version-satisfies-range.js'
99import isArchivedVersion from '../lib/is-archived-version.js'
1010import got from 'got'
1111import readJsonFile from '../lib/read-json-file.js'
12+ import { cacheControlFactory } from './cache-control.js'
1213const archivedRedirects = readJsonFile (
1314 './lib/redirects/static/archived-redirects-from-213-to-217.json'
1415)
1516const archivedFrontmatterFallbacks = readJsonFile (
1617 './lib/redirects/static/archived-frontmatter-fallbacks.json'
1718)
1819
20+ const cacheControl = cacheControlFactory ( 60 * 60 * 24 * 365 )
21+
1922async function getRemoteJSON ( url ) {
2023 if ( _getRemoteJSONCache . has ( url ) ) {
2124 return _getRemoteJSONCache . get ( url )
@@ -42,6 +45,7 @@ export default async function archivedEnterpriseVersions(req, res, next) {
4245 req . path . startsWith ( '/en/' ) &&
4346 versionSatisfiesRange ( requestedVersion , `<${ firstVersionDeprecatedOnNewSite } ` )
4447 ) {
48+ cacheControl ( res )
4549 return res . redirect ( 301 , req . baseUrl + req . path . replace ( / ^ \/ e n / , '' ) )
4650 }
4751
@@ -53,6 +57,7 @@ export default async function archivedEnterpriseVersions(req, res, next) {
5357 ) {
5458 const redirect = archivedRedirects [ req . path ]
5559 if ( redirect && redirect !== req . path ) {
60+ cacheControl ( res )
5661 return res . redirect ( 301 , redirect )
5762 }
5863 }
@@ -64,6 +69,7 @@ export default async function archivedEnterpriseVersions(req, res, next) {
6469 // make redirects found via redirects.json redirect with a 301
6570 if ( redirectJson [ req . path ] ) {
6671 res . set ( 'x-robots-tag' , 'noindex' )
72+ cacheControl ( res )
6773 return res . redirect ( 301 , redirectJson [ req . path ] )
6874 }
6975 } catch ( err ) {
@@ -78,6 +84,7 @@ export default async function archivedEnterpriseVersions(req, res, next) {
7884 // make stubbed redirect files (which exist in versions <2.13) redirect with a 301
7985 const staticRedirect = r . body . match ( patterns . staticRedirect )
8086 if ( staticRedirect ) {
87+ cacheControl ( res )
8188 return res . redirect ( 301 , staticRedirect [ 1 ] )
8289 }
8390
@@ -87,6 +94,7 @@ export default async function archivedEnterpriseVersions(req, res, next) {
8794 for ( const fallbackRedirect of getFallbackRedirects ( req , requestedVersion ) || [ ] ) {
8895 try {
8996 await got ( getProxyPath ( fallbackRedirect , requestedVersion ) )
97+ cacheControl ( res )
9098 return res . redirect ( 301 , fallbackRedirect )
9199 } catch ( err ) {
92100 // noop
0 commit comments