Skip to content

Commit

Permalink
updated the pagelist middleware so it only returns english pagelinks …
Browse files Browse the repository at this point in the history
…(#52342)
  • Loading branch information
Saturn226 authored Sep 18, 2024
1 parent 64046b6 commit e37f937
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/pagelist/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ router.get('/v1/:product@:version', (req: ExtendedRequest, res: Response) => {

// we filter the permalinks to get only our target version
const filteredPermalinks = keys.filter((key) => versionMatcher(key, `${product}@${version}`))
const expression = /^\/en/

if (!filteredPermalinks.length) {
res.status(400).type('text').send('Invalid version')
return
}

//right now we only need english permalinks perhaps we can use the language from the request in the future
const englishPermalinks = filteredPermalinks.filter((permalink) => expression.test(permalink))

defaultCacheControl(res)

// new line added at the end so `wc` works as expected with `-l` and `-w`.
res.type('text').send(filteredPermalinks.join('\n').concat('\n'))
res.type('text').send(englishPermalinks.join('\n').concat('\n'))
})

router.get('/:product@:version', (req, res) => {
Expand Down
10 changes: 10 additions & 0 deletions src/pagelist/tests/pagelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,14 @@ describe.each(allVersionKeys)('pagelist api for %s', async (versionKey) => {
expect(permalink).toMatch(expression)
})
})

test('only returns urls that contain /en', async () => {
const expression = new RegExp(`^/en(/${nonEnterpriseDefaultVersion})?/?.*`)
res.body
.trim()
.split('\n')
.forEach((permalink: string) => {
expect(permalink).toMatch(expression)
})
})
})

0 comments on commit e37f937

Please sign in to comment.