1
0
mirror of synced 2026-01-04 00:06:20 -05:00

Merge branch 'main' into repo-sync

This commit is contained in:
Octomerger Bot
2023-04-25 10:05:44 -04:00
committed by GitHub
2 changed files with 8 additions and 30 deletions

View File

@@ -22,9 +22,6 @@ env:
# Setting this will activate the jest tests that depend on actually
# sending real search queries to Elasticsearch
ELASTICSEARCH_URL: http://localhost:9200/
# Hopefully the name is clear enough. By enabling this, we're testing
# the future code.
ENABLE_SEARCH_RESULTS_PAGE: true
jobs:
figureOutMatrix:

View File

@@ -25,35 +25,16 @@ export default function handleRedirects(req, res, next) {
let redirect = req.path
let queryParams = req._parsedUrl.query
// If process.env.ENABLE_SEARCH_RESULTS_PAGE isn't set, you can't go to the
// dedicated search results page.
// If that's the case, use the "old redirect" where all it does is
// "correcting" the old query string 'q' to 'query'.
if (!process.env.ENABLE_SEARCH_RESULTS_PAGE && 'q' in req.query && !('query' in req.query)) {
// update old-style query params (#9467)
const newQueryParams = new URLSearchParams(queryParams)
newQueryParams.set('query', newQueryParams.get('q'))
newQueryParams.delete('q')
return res.redirect(301, `${req.path}?${newQueryParams.toString()}`)
}
// If process.env.ENABLE_SEARCH_RESULTS_PAGE is set, the dedicated search
// result page is ready. If that's the case, we can redirect to
// `/$locale/search?query=...` from `/foo/bar?query=...` or from
// (the old style) `/foo/bar/?q=...`
// Redirect `/some/uri?q=stuff` to `/en/search?query=stuff`
// Redirect `/some/uri?query=stuff` to `/en/search?query=stuff`
// Redirect `/fr/version@latest/some/uri?query=stuff`
// to `/fr/version@latest/search?query=stuff`
// The `q` param is deprecated, but we still need to support it in case
// there are links out there that use it.
if (
process.env.ENABLE_SEARCH_RESULTS_PAGE &&
('q' in req.query ||
('query' in req.query &&
!(req.path.endsWith('/search') || req.path.startsWith('/api/search'))))
'q' in req.query ||
('query' in req.query && !(req.path.endsWith('/search') || req.path.startsWith('/api/search')))
) {
// If you had the old legacy format of /some/uri?q=stuff
// it needs to redirect to /en/search?query=stuff or
// /some/uri?query=stuff depending on if ENABLE_SEARCH_RESULTS_PAGE has been
// set up.
// If you have the new format of /some/uri?query=stuff it too needs
// to redirect to /en/search?query=stuff
// ...or /en/{version}/search?query=stuff
const language = getLanguage(req)
const sp = new URLSearchParams(req.query)
if (sp.has('q') && !sp.has('query')) {