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