Add warning for API export (#8250)

This commit is contained in:
Lukáš Huvar 2019-08-06 00:46:02 +02:00 committed by GitHub
parent b31c296730
commit abcaba7f7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View file

@ -19,6 +19,7 @@ import {
import createProgress from 'tty-aware-progress'
import { promisify } from 'util'
import { recursiveDelete } from '../lib/recursive-delete'
import { API_ROUTE } from '../lib/constants'
import { formatAmpMessages } from '../build/output/index'
const mkdirp = promisify(mkdirpModule)
@ -35,6 +36,7 @@ export default async function (dir, options, configuration) {
const threads = options.threads || Math.max(cpus().length - 1, 1)
const distDir = join(dir, nextConfig.distDir)
const subFolders = nextConfig.exportTrailingSlash
let apiPage = false
if (!options.buildExport && nextConfig.target !== 'server') {
throw new Error(
@ -60,7 +62,20 @@ export default async function (dir, options, configuration) {
for (const page of pages) {
// _document and _app are not real pages
// _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
}

View file

@ -10,6 +10,7 @@ import {
renderViaHTTP,
nextBuild,
nextStart,
runNextCommand,
File
} from 'next-test-utils'
import json from '../big.json'
@ -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 () => {
const data = await fetchViaHTTP(
appPort,