Skip to content

repo sync #25210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
35 changes: 8 additions & 27 deletions middleware/redirects/handle-redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down