404 on any /_next/image request (#31052)
This commit is contained in:
@@ -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
12
tests/routing/next.js
Normal 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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user