1
1
import patterns from '../../lib/patterns.js'
2
2
import { URL } from 'url'
3
3
import { pathLanguagePrefixed } from '../../lib/languages.js'
4
+ import { deprecatedWithFunctionalRedirects } from '../../lib/enterprise-server-releases.js'
4
5
import getRedirect from '../../lib/get-redirect.js'
5
6
import { cacheControlFactory } from '../cache-control.js'
6
7
@@ -65,7 +66,7 @@ export default function handleRedirects(req, res, next) {
65
66
// But for example, a `/authentication/connecting-to-github-with-ssh`
66
67
// needs to become `/en/authentication/connecting-to-github-with-ssh`
67
68
const possibleRedirectTo = `/en${ req . path } `
68
- if ( possibleRedirectTo in req . context . pages ) {
69
+ if ( possibleRedirectTo in req . context . pages || isDeprecatedAdminReleaseNotes ( req . path ) ) {
69
70
const language = getLanguage ( req )
70
71
71
72
// Note, it's important to use `req.url` here and not `req.path`
@@ -82,7 +83,10 @@ export default function handleRedirects(req, res, next) {
82
83
}
83
84
84
85
// do not redirect if the redirected page can't be found
85
- if ( ! req . context . pages [ removeQueryParams ( redirect ) ] && ! redirect . includes ( '://' ) ) {
86
+ if (
87
+ ! ( req . context . pages [ removeQueryParams ( redirect ) ] || isDeprecatedAdminReleaseNotes ( req . path ) ) &&
88
+ ! redirect . includes ( '://' )
89
+ ) {
86
90
// display error on the page in development, but not in production
87
91
// include final full redirect path in the message
88
92
if ( process . env . NODE_ENV !== 'production' && req . context ) {
@@ -134,3 +138,20 @@ function usePermanentRedirect(req) {
134
138
function removeQueryParams ( redirect ) {
135
139
return new URL ( redirect , 'https://docs.github.com' ) . pathname
136
140
}
141
+
142
+ function isDeprecatedAdminReleaseNotes ( path ) {
143
+ // When we rewrote how redirects work, from a lookup model to a
144
+ // functional model, the enterprise-server releases that got
145
+ // deprecated since then fall between the cracks. Especially
146
+ // for custom NextJS page-like pages like /admin/release-notes
147
+ // These URLs don't come from any remaining .json lookup file
148
+ // and they're not active pages either (e.g. req.context.pages)
149
+ if ( path . includes ( 'admin/release-notes' ) ) {
150
+ for ( const version of deprecatedWithFunctionalRedirects ) {
151
+ if ( path . includes ( `enterprise-server@${ version } ` ) ) {
152
+ return true
153
+ }
154
+ }
155
+ }
156
+ return false
157
+ }
0 commit comments