Skip to content

Commit

Permalink
Image Optimizer API should 404 when loader is not default
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed Oct 24, 2020
1 parent 6d3b065 commit b5d1bf1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/next/next-server/server/image-optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ export async function imageOptimizer(
parsedUrl: UrlWithParsedQuery
) {
const { nextConfig, distDir } = server
const { sizes = [], domains = [] } = nextConfig?.images || {}
const { sizes = [], domains = [], loader } = nextConfig?.images || {}

if (loader !== 'default') {
await server.render404(req, res, parsedUrl)
return { finished: true }
}

const { headers } = req
const { url, w, q } = parsedUrl.query
const mimeType = mediaType(headers.accept, MIME_TYPES) || ''
Expand Down
25 changes: 25 additions & 0 deletions test/integration/image-optimizer/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,29 @@ describe('Image Optimizer', () => {

runTests({ w: size, isDev: false, domains })
})

describe('dev support next.config.js cloudinary loader', () => {
beforeAll(async () => {
const json = JSON.stringify({
images: {
loader: 'cloudinary',
path: 'https://example.com/act123/',
},
})
nextConfig.replace('{ /* replaceme */ }', json)
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
nextConfig.restore()
await fs.remove(imagesDir)
})
it('should 404 when loader is not default', async () => {
const query = { w: 320, q: 90, url: '/test.svg' }
const opts = { headers: { accept: 'image/webp' } }
const res = await fetchViaHTTP(appPort, '/_next/image', query, opts)
expect(res.status).toBe(404)
})
})
})

0 comments on commit b5d1bf1

Please sign in to comment.