Skip to content

Commit

Permalink
Merge pull request github#32791 from github/repo-sync
Browse files Browse the repository at this point in the history
Repo sync
  • Loading branch information
docs-bot authored May 3, 2024
2 parents 0e2990a + 2bb7ee2 commit 608db5c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/frame/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export default function (app) {
app.get('/_ip', remoteIP)
app.get('/_build', buildInfo)
app.use('/producticons', productIcons)
app.use('/manifest.json', asyncMiddleware(manifestJson))
app.use(asyncMiddleware(manifestJson))

// Things like `/api` sets their own Fastly surrogate keys.
// Now that the `req.language` is known, set it for the remaining endpoints
Expand Down
12 changes: 11 additions & 1 deletion src/frame/middleware/manifest-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ const ICONS = [
'./assets/images/site/apple-touch-icon-512x512.png',
]

export default async function manifestJson(req, res) {
export default async function manifestJson(req, res, next) {
if (!req.url.startsWith('/manifest.json')) {
return next()
}

if (req.url !== '/manifest.json') {
// E.g. `/manifest.json/anything` or `/manifest.json?foo=bar`
defaultCacheControl(res)
return res.redirect(302, '/manifest.json')
}

// This is modelled after https://github.com/manifest.json
const manifest = {
// In the future we might want to have a different manifest for each
Expand Down
16 changes: 16 additions & 0 deletions src/frame/tests/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,20 @@ describe('manifest', () => {
}),
)
})

test('/manifest.json is the only valid URL (query string)', async () => {
const res = await get('/manifest.json?foo=bar')
expect(res.statusCode).toBe(302)
expect(res.headers.location).toBe('/manifest.json')
expect(res.headers['cache-control']).toMatch(/public/)
expect(res.headers['cache-control']).toMatch(/max-age=\d\d+/)
})

test('/manifest.json is the only valid URL (more path)', async () => {
const res = await get('/manifest.json/something/else')
expect(res.statusCode).toBe(302)
expect(res.headers.location).toBe('/manifest.json')
expect(res.headers['cache-control']).toMatch(/public/)
expect(res.headers['cache-control']).toMatch(/max-age=\d\d+/)
})
})

0 comments on commit 608db5c

Please sign in to comment.