提交 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 } = {
reactMode: 'legacy',
workerThreads: false,
basePath: '',
static404: false,
static404: true,
},
future: {
excludeDefaultMomentLocales: false,
......
......@@ -1116,7 +1116,7 @@ export default class Server {
let result: null | LoadComponentsReturnType = null
// 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 {
result = await this.findPageComponents('/_errors/404')
} catch (err) {
......
......@@ -20,7 +20,6 @@ const static404 = join(
const appPage = join(appDir, 'pages/_app.js')
const errorPage = join(appDir, 'pages/_error.js')
const buildId = `generateBuildId: () => 'test-id'`
const experimentalConfig = `experimental: { static404: true }`
let app
let appPort
......@@ -34,7 +33,10 @@ describe('Static 404 page', () => {
describe('With config disabled', () => {
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)
expect(await fs.exists(static404)).toBe(false)
})
......@@ -42,10 +44,7 @@ describe('Static 404 page', () => {
describe('With config enabled', () => {
beforeEach(() =>
fs.writeFile(
nextConfig,
`module.exports = { ${buildId}, ${experimentalConfig} }`
)
fs.writeFile(nextConfig, `module.exports = { ${buildId} }`)
)
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.
先完成此消息的编辑!
想要评论请 注册