Unverified Commit abcaba7f authored by Lukáš Huvar's avatar Lukáš Huvar Committed by GitHub

Add warning for API export (#8250)

parent b31c2967
...@@ -19,6 +19,7 @@ import { ...@@ -19,6 +19,7 @@ import {
import createProgress from 'tty-aware-progress' import createProgress from 'tty-aware-progress'
import { promisify } from 'util' import { promisify } from 'util'
import { recursiveDelete } from '../lib/recursive-delete' import { recursiveDelete } from '../lib/recursive-delete'
import { API_ROUTE } from '../lib/constants'
import { formatAmpMessages } from '../build/output/index' import { formatAmpMessages } from '../build/output/index'
const mkdirp = promisify(mkdirpModule) const mkdirp = promisify(mkdirpModule)
...@@ -35,6 +36,7 @@ export default async function (dir, options, configuration) { ...@@ -35,6 +36,7 @@ export default async function (dir, options, configuration) {
const threads = options.threads || Math.max(cpus().length - 1, 1) const threads = options.threads || Math.max(cpus().length - 1, 1)
const distDir = join(dir, nextConfig.distDir) const distDir = join(dir, nextConfig.distDir)
const subFolders = nextConfig.exportTrailingSlash const subFolders = nextConfig.exportTrailingSlash
let apiPage = false
if (!options.buildExport && nextConfig.target !== 'server') { if (!options.buildExport && nextConfig.target !== 'server') {
throw new Error( throw new Error(
...@@ -60,7 +62,20 @@ export default async function (dir, options, configuration) { ...@@ -60,7 +62,20 @@ export default async function (dir, options, configuration) {
for (const page of pages) { for (const page of pages) {
// _document and _app are not real pages // _document and _app are not real pages
// _error is exported as 404.html later on // _error is exported as 404.html later on
if (page === '/_document' || page === '/_app' || page === '/_error') { const isApiRoute = page.match(API_ROUTE)
// Warn about API pages export
if (isApiRoute && !apiPage) {
apiPage = true
log(` API pages are not supported in export`)
}
if (
page === '/_document' ||
page === '/_app' ||
page === '/_error' ||
isApiRoute
) {
continue continue
} }
......
...@@ -10,6 +10,7 @@ import { ...@@ -10,6 +10,7 @@ import {
renderViaHTTP, renderViaHTTP,
nextBuild, nextBuild,
nextStart, nextStart,
runNextCommand,
File File
} from 'next-test-utils' } from 'next-test-utils'
import json from '../big.json' import json from '../big.json'
...@@ -285,6 +286,17 @@ function runTests (serverless = false) { ...@@ -285,6 +286,17 @@ function runTests (serverless = false) {
} }
}) })
if (!serverless) {
it('should warn about API export', async () => {
const { stdout } = await runNextCommand(['export', appDir], {
stdout: true,
stderr: true
})
expect(stdout).toContain('API pages are not supported in export')
})
}
it('should return data on dynamic optional nested route', async () => { it('should return data on dynamic optional nested route', async () => {
const data = await fetchViaHTTP( const data = await fetchViaHTTP(
appPort, appPort,
......
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