1
0
mirror of synced 2025-12-19 18:10:59 -05:00

404 on any /_next/image request (#31052)

This commit is contained in:
Peter Bengtsson
2022-09-22 21:55:30 +02:00
committed by GitHub
parent bcf6f2b18e
commit 35e91423d0
2 changed files with 20 additions and 0 deletions

View File

@@ -8,6 +8,14 @@ export const nextHandleRequest = nextApp.getRequestHandler()
await nextApp.prepare()
function renderPageWithNext(req, res, next) {
// We currently don't use next/image for any images.
// We don't even have `sharp` installed.
// This could change in the future but right now can just 404 on these
// so we don't have to deal with any other errors.
if (req.path.startsWith('/_next/image')) {
return next(404)
}
const isNextDataRequest = req.path.startsWith('/_next') && !req.path.startsWith('/_next/data')
if (isNextDataRequest) {

12
tests/routing/next.js Normal file
View File

@@ -0,0 +1,12 @@
import { describe, expect, jest, test } from '@jest/globals'
import { get } from '../helpers/e2etest.js'
describe('redirects', () => {
jest.setTimeout(60 * 1000)
test('any _next/image request should 404', async () => {
const res = await get('/_next/image?what=ever')
expect(res.statusCode).toBe(404)
})
})