提交 f711b77b 编写于 作者: J JJ Kasper 提交者: Tim Neutkens

Enable static 404 config to allow static 404 page when availab… (#10290)

* Enable static 404 config to allow static 404 page when available

* Update static 404 suite

* Fix invalid params test case
上级 bd3662b5
...@@ -52,7 +52,7 @@ const defaultConfig: { [key: string]: any } = { ...@@ -52,7 +52,7 @@ const defaultConfig: { [key: string]: any } = {
reactMode: 'legacy', reactMode: 'legacy',
workerThreads: false, workerThreads: false,
basePath: '', basePath: '',
static404: false, static404: true,
}, },
future: { future: {
excludeDefaultMomentLocales: false, excludeDefaultMomentLocales: false,
......
...@@ -1116,7 +1116,7 @@ export default class Server { ...@@ -1116,7 +1116,7 @@ export default class Server {
let result: null | LoadComponentsReturnType = null let result: null | LoadComponentsReturnType = null
// use static 404 page if available and is 404 response // use static 404 page if available and is 404 response
if (this.nextConfig.experimental.static404 && err === null) { if (this.nextConfig.experimental.static404 && res.statusCode === 404) {
try { try {
result = await this.findPageComponents('/_errors/404') result = await this.findPageComponents('/_errors/404')
} catch (err) { } catch (err) {
......
...@@ -20,7 +20,6 @@ const static404 = join( ...@@ -20,7 +20,6 @@ const static404 = join(
const appPage = join(appDir, 'pages/_app.js') const appPage = join(appDir, 'pages/_app.js')
const errorPage = join(appDir, 'pages/_error.js') const errorPage = join(appDir, 'pages/_error.js')
const buildId = `generateBuildId: () => 'test-id'` const buildId = `generateBuildId: () => 'test-id'`
const experimentalConfig = `experimental: { static404: true }`
let app let app
let appPort let appPort
...@@ -34,7 +33,10 @@ describe('Static 404 page', () => { ...@@ -34,7 +33,10 @@ describe('Static 404 page', () => {
describe('With config disabled', () => { describe('With config disabled', () => {
it('should not have exported static 404 page', async () => { it('should not have exported static 404 page', async () => {
await fs.writeFile(nextConfig, `module.exports = { ${buildId} }`) await fs.writeFile(
nextConfig,
`module.exports = { ${buildId}, experimental: { static404: false } }`
)
await nextBuild(appDir) await nextBuild(appDir)
expect(await fs.exists(static404)).toBe(false) expect(await fs.exists(static404)).toBe(false)
}) })
...@@ -42,10 +44,7 @@ describe('Static 404 page', () => { ...@@ -42,10 +44,7 @@ describe('Static 404 page', () => {
describe('With config enabled', () => { describe('With config enabled', () => {
beforeEach(() => beforeEach(() =>
fs.writeFile( fs.writeFile(nextConfig, `module.exports = { ${buildId} }`)
nextConfig,
`module.exports = { ${buildId}, ${experimentalConfig} }`
)
) )
it('should export 404 page without custom _error', async () => { it('should export 404 page without custom _error', async () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册