Commit b0b1c320 authored by Joe Haddad's avatar Joe Haddad Committed by Tim Neutkens

Experimentalize `public/` (#7771)

* Experimentalize `public/`

* Update tests for publicDirectory config
parent f2049352
......@@ -37,6 +37,7 @@ const defaultConfig: { [key: string]: any } = {
flyingShuttle: false,
asyncToPromises: false,
documentMiddleware: false,
publicDirectory: false,
},
}
......
......@@ -236,7 +236,10 @@ export default class Server {
},
]
if (fs.existsSync(this.publicDir)) {
if (
this.nextConfig.experimental.publicDirectory &&
fs.existsSync(this.publicDir)
) {
routes.push(...this.generatePublicRoutes())
}
......
......@@ -271,9 +271,14 @@ export default class DevServer extends Server {
})
} catch (err) {
if (err.code === 'ENOENT') {
// Try to send a public file and let servePublic handle the request from here
await this.servePublic(req, res, pathname)
return null
if (this.nextConfig.experimental.publicDirectory) {
// Try to send a public file and let servePublic handle the request from here
await this.servePublic(req, res, pathname)
return null
} else {
res.statusCode = 404
return this.renderErrorToHTML(null, req, res, pathname, query)
}
}
if (!this.quiet) console.error(err)
}
......
......@@ -4,6 +4,9 @@ module.exports = {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60
},
experimental: {
publicDirectory: true
},
webpack (config) {
config.module.rules.push({
test: /pages[\\/]hmr[\\/]about/,
......
......@@ -9,6 +9,9 @@ module.exports = phase => {
serverRuntimeConfig: {
bar: 'bar'
},
experimental: {
publicDirectory: true
},
exportTrailingSlash: true,
exportPathMap: function () {
return {
......
......@@ -2,5 +2,8 @@ module.exports = {
onDemandEntries: {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60
},
experimental: {
publicDirectory: true
}
}
......@@ -3,5 +3,8 @@ module.exports = {
onDemandEntries: {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60
},
experimental: {
publicDirectory: true
}
}
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