Commit 718a36e1 authored by Lukáš Huvar's avatar Lukáš Huvar Committed by Tim Neutkens

Fix build for API routes conflict pages (#7992)

* Fixes #7991

* Fix tests
parent 571eb981
......@@ -68,7 +68,7 @@ export function createEntrypoints(
Object.keys(pages).forEach(page => {
const absolutePagePath = pages[page]
const bundleFile = page === '/' ? '/index.js' : `${page}.js`
const isApiRoute = bundleFile.startsWith('/api')
const isApiRoute = bundleFile.startsWith('/api/')
const bundlePath = join('static', buildId, 'pages', bundleFile)
......
......@@ -39,7 +39,7 @@ const nextServerlessLoader: loader.Loader = function() {
'/'
)
if (page.startsWith('/api')) {
if (page.startsWith('/api/')) {
return `
${
isDynamicRoute(page)
......
export default () => <div>API - conflict</div>
......@@ -9,6 +9,7 @@ import {
fetchViaHTTP,
renderViaHTTP,
nextBuild,
nextStart,
File
} from 'next-test-utils'
import json from '../big.json'
......@@ -35,6 +36,15 @@ function runTests (serverless = false) {
expect(status).toEqual(404)
})
it('should not conflict with /api routes', async () => {
const port = await findPort()
await nextBuild(appDir)
const app = await nextStart(appDir, port)
const res = await fetchViaHTTP(port, '/api-conflict')
expect(res.status).not.toEqual(404)
killApp(app)
})
it('should return custom error', async () => {
const data = await fetchViaHTTP(appPort, '/api/error', null, {})
const json = await data.json()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment