-
Notifications
You must be signed in to change notification settings - Fork 26k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show warning if next export detects an API route (#8257)
* Throw error if next export detects an api route * Moved the test to the export tests * Added missing comma * Move the API route comment * Add comma after replace * Show a warning instead
- Loading branch information
1 parent
f01af7c
commit 36aabe0
Showing
7 changed files
with
66 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# API routes in Static export | ||
|
||
#### Why This Warning Occurred | ||
|
||
An `exportPathMap` path was matched to an API route. `next export` will not prerender API routes to HTML. | ||
|
||
#### Possible Ways to Fix It | ||
|
||
Remove any paths using API routes from your `exportPathMap` in `next.config.js`. | ||
|
||
### Useful Links | ||
|
||
- [Static HTML export](https://github.com/zeit/next.js#static-html-export) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default (req, res) => { | ||
res.send('Hello World') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* eslint-env jest */ | ||
import { join } from 'path' | ||
import { File, runNextCommand } from 'next-test-utils' | ||
|
||
export default function (context) { | ||
describe('API routes export', () => { | ||
const nextConfig = new File(join(context.appDir, 'next.config.js')) | ||
|
||
beforeEach(() => { | ||
nextConfig.replace('// API route', `'/data': { page: '/api/data' },`) | ||
}) | ||
afterEach(() => { | ||
nextConfig.restore() | ||
}) | ||
|
||
it('Should throw if a route is matched', async () => { | ||
const outdir = join(context.appDir, 'outApi') | ||
const { stdout } = await runNextCommand( | ||
['export', context.appDir, '--outdir', outdir], | ||
{ stdout: true } | ||
) | ||
|
||
expect(stdout).toContain( | ||
'https://err.sh/zeit/next.js/api-routes-static-export' | ||
) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters