Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Optimization API should 404 when loader is not default #18211

Merged
merged 1 commit into from Oct 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/next/next-server/server/image-optimizer.ts
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)
ijjk marked this conversation as resolved.
Show resolved Hide resolved
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
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)
})
})
})