mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Make sure pages bundles are served correctly
This commit is contained in:
parent
95fe683c58
commit
963695820f
|
@ -1,4 +1,4 @@
|
||||||
/* global window, document, __NEXT_DATA__ */
|
/* global window, document */
|
||||||
import EventEmitter from './EventEmitter'
|
import EventEmitter from './EventEmitter'
|
||||||
|
|
||||||
const webpackModule = module
|
const webpackModule = module
|
||||||
|
@ -69,11 +69,7 @@ export default class PageLoader {
|
||||||
|
|
||||||
loadScript (route) {
|
loadScript (route) {
|
||||||
route = this.normalizeRoute(route)
|
route = this.normalizeRoute(route)
|
||||||
let scriptRoute = route
|
const scriptRoute = route === '/' ? '/index.js' : `${route}.js`
|
||||||
|
|
||||||
if (__NEXT_DATA__.nextExport) {
|
|
||||||
scriptRoute = route === '/' ? '/index.js' : `${route}.js`
|
|
||||||
}
|
|
||||||
|
|
||||||
const script = document.createElement('script')
|
const script = document.createElement('script')
|
||||||
const url = `${this.assetPrefix}/_next/${encodeURIComponent(this.buildId)}/page${scriptRoute}`
|
const url = `${this.assetPrefix}/_next/${encodeURIComponent(this.buildId)}/page${scriptRoute}`
|
||||||
|
|
|
@ -194,12 +194,12 @@ export default class Server {
|
||||||
await this.serveStatic(req, res, p)
|
await this.serveStatic(req, res, p)
|
||||||
},
|
},
|
||||||
|
|
||||||
'/_next/:buildId/page/:path*': async (req, res, params) => {
|
'/_next/:buildId/page/:path*.js': async (req, res, params) => {
|
||||||
const paths = params.path || ['']
|
const paths = params.path || ['']
|
||||||
// URL is asks for ${page}.js (to support loading assets from static dirs)
|
// URL is asks for ${page}.js (to support loading assets from static dirs)
|
||||||
// But there's no .js in the actual page.
|
// But there's no .js in the actual page.
|
||||||
// So, we need to remove .js to get the page name.
|
// So, we need to remove .js to get the page name.
|
||||||
const page = `/${paths.join('/')}`.replace('.js', '')
|
const page = `/${paths.join('/')}`
|
||||||
|
|
||||||
if (!this.handleBuildId(params.buildId, res)) {
|
if (!this.handleBuildId(params.buildId, res)) {
|
||||||
const error = new Error('INVALID_BUILD_ID')
|
const error = new Error('INVALID_BUILD_ID')
|
||||||
|
@ -222,8 +222,11 @@ export default class Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const p = join(this.dir, this.dist, 'bundles', 'pages', paths.join('/'))
|
let p = join(this.dir, this.dist, 'bundles', 'pages', paths.join('/'))
|
||||||
await this.serveStatic(req, res, p)
|
if (!fs.existsSync(`${p}.js`)) {
|
||||||
|
p = join(p, 'index') // It's possible to have index.js in a subfolder
|
||||||
|
}
|
||||||
|
await this.serveStatic(req, res, `${p}.js`)
|
||||||
},
|
},
|
||||||
|
|
||||||
// It's very important keep this route's param optional.
|
// It's very important keep this route's param optional.
|
||||||
|
|
Loading…
Reference in a new issue