1
0
mirror of synced 2026-01-23 12:02:29 -05:00

Merge pull request #18017 from github/ghes-latest-redirect

Support GHES @latest redirect
This commit is contained in:
Sarah Schneider
2021-03-02 10:05:46 -05:00
committed by GitHub
4 changed files with 15 additions and 5 deletions

View File

@@ -82,6 +82,10 @@ module.exports = function getOldPathsFromPath (currentPath, languageCode, curren
oldPaths.add(oldPath
.replace(`/enterprise-server@${latest}`, '/enterprise-server'))
// create old path /enterprise-server@latest from new path /enterprise-server@<latest>
oldPaths.add(oldPath
.replace(`/enterprise-server@${latest}`, '/enterprise-server@latest'))
if (!patterns.adminProduct.test(oldPath)) {
// create old path /enterprise/<version>/user/foo from new path /enterprise-server@<version>/foo
oldPaths.add(currentPath

View File

@@ -2,19 +2,19 @@ const developerRedirects = require('../redirects/static/developer')
const { latest } = require('../../lib/enterprise-server-releases')
const latestDevRedirects = {}
// Replace hardcoded 'latest' with real value
// Replace hardcoded 'latest' with real value in the redirected path
Object.entries(developerRedirects).forEach(([oldPath, newPath]) => {
latestDevRedirects[oldPath] = newPath.replace('enterprise-server@latest', `enterprise-server@${latest}`)
})
// This function runs at server warmup and precompiles possible redirect routes.
// It outputs them in key-value pairs within a neat Javascript object: { oldPath: newPath }
module.exports = function precompileRedirects (pageList) {
module.exports = async function precompileRedirects (pageList) {
const allRedirects = Object.assign({}, latestDevRedirects)
// CURRENT PAGES PERMALINKS AND FRONTMATTER
// create backwards-compatible old paths for page permalinks and frontmatter redirects
pageList.forEach(page => Object.assign(allRedirects, page.buildRedirects()))
await Promise.all(pageList.map(async (page) => Object.assign(allRedirects, page.buildRedirects())))
return allRedirects
}

View File

@@ -9,7 +9,7 @@ const loadSiteTree = require('./site-tree')
const dog = {
loadPages: statsd.asyncTimer(loadPages, 'load_pages'),
loadPageMap: statsd.asyncTimer(loadPageMap, 'load_page_map'),
loadRedirects: statsd.timer(loadRedirects, 'load_redirects'),
loadRedirects: statsd.asyncTimer(loadRedirects, 'load_redirects'),
loadSiteData: statsd.timer(loadSiteData, 'load_site_data'),
loadSiteTree: statsd.asyncTimer(loadSiteTree, 'load_site_tree')
}
@@ -52,7 +52,7 @@ async function warmServer () {
}
if (!redirects) {
redirects = dog.loadRedirects(pageList, pageMap)
redirects = await dog.loadRedirects(pageList, pageMap)
}
if (!siteTree) {

View File

@@ -159,6 +159,12 @@ describe('redirects', () => {
expect(res.statusCode).toBe(301)
expect(res.headers.location).toBe(japaneseEnterpriseHome)
})
test('hardcoded @latest redirects to latest version', async () => {
const res = await get('/en/enterprise-server@latest')
expect(res.statusCode).toBe(301)
expect(res.headers.location).toBe(enterpriseHome)
})
})
describe('2.13+ deprecated enterprise', () => {