@@ -9,13 +9,16 @@ import versionSatisfiesRange from '../lib/version-satisfies-range.js'
9
9
import isArchivedVersion from '../lib/is-archived-version.js'
10
10
import got from 'got'
11
11
import readJsonFile from '../lib/read-json-file.js'
12
+ import { cacheControlFactory } from './cache-control.js'
12
13
const archivedRedirects = readJsonFile (
13
14
'./lib/redirects/static/archived-redirects-from-213-to-217.json'
14
15
)
15
16
const archivedFrontmatterFallbacks = readJsonFile (
16
17
'./lib/redirects/static/archived-frontmatter-fallbacks.json'
17
18
)
18
19
20
+ const cacheControl = cacheControlFactory ( 60 * 60 * 24 * 365 )
21
+
19
22
async function getRemoteJSON ( url ) {
20
23
if ( _getRemoteJSONCache . has ( url ) ) {
21
24
return _getRemoteJSONCache . get ( url )
@@ -42,6 +45,7 @@ export default async function archivedEnterpriseVersions(req, res, next) {
42
45
req . path . startsWith ( '/en/' ) &&
43
46
versionSatisfiesRange ( requestedVersion , `<${ firstVersionDeprecatedOnNewSite } ` )
44
47
) {
48
+ cacheControl ( res )
45
49
return res . redirect ( 301 , req . baseUrl + req . path . replace ( / ^ \/ e n / , '' ) )
46
50
}
47
51
@@ -53,6 +57,7 @@ export default async function archivedEnterpriseVersions(req, res, next) {
53
57
) {
54
58
const redirect = archivedRedirects [ req . path ]
55
59
if ( redirect && redirect !== req . path ) {
60
+ cacheControl ( res )
56
61
return res . redirect ( 301 , redirect )
57
62
}
58
63
}
@@ -64,6 +69,7 @@ export default async function archivedEnterpriseVersions(req, res, next) {
64
69
// make redirects found via redirects.json redirect with a 301
65
70
if ( redirectJson [ req . path ] ) {
66
71
res . set ( 'x-robots-tag' , 'noindex' )
72
+ cacheControl ( res )
67
73
return res . redirect ( 301 , redirectJson [ req . path ] )
68
74
}
69
75
} catch ( err ) {
@@ -78,6 +84,7 @@ export default async function archivedEnterpriseVersions(req, res, next) {
78
84
// make stubbed redirect files (which exist in versions <2.13) redirect with a 301
79
85
const staticRedirect = r . body . match ( patterns . staticRedirect )
80
86
if ( staticRedirect ) {
87
+ cacheControl ( res )
81
88
return res . redirect ( 301 , staticRedirect [ 1 ] )
82
89
}
83
90
@@ -87,6 +94,7 @@ export default async function archivedEnterpriseVersions(req, res, next) {
87
94
for ( const fallbackRedirect of getFallbackRedirects ( req , requestedVersion ) || [ ] ) {
88
95
try {
89
96
await got ( getProxyPath ( fallbackRedirect , requestedVersion ) )
97
+ cacheControl ( res )
90
98
return res . redirect ( 301 , fallbackRedirect )
91
99
} catch ( err ) {
92
100
// noop
0 commit comments