提交 96369582 编写于 作者: T Tim Neutkens

Make sure pages bundles are served correctly

上级 95fe683c
/* global window, document, __NEXT_DATA__ */
/* global window, document */
import EventEmitter from './EventEmitter'
const webpackModule = module
......@@ -69,11 +69,7 @@ export default class PageLoader {
loadScript (route) {
route = this.normalizeRoute(route)
let scriptRoute = route
if (__NEXT_DATA__.nextExport) {
scriptRoute = route === '/' ? '/index.js' : `${route}.js`
}
const scriptRoute = route === '/' ? '/index.js' : `${route}.js`
const script = document.createElement('script')
const url = `${this.assetPrefix}/_next/${encodeURIComponent(this.buildId)}/page${scriptRoute}`
......
......@@ -194,12 +194,12 @@ export default class Server {
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 || ['']
// URL is asks for ${page}.js (to support loading assets from static dirs)
// But there's no .js in the actual page.
// 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)) {
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('/'))
await this.serveStatic(req, res, p)
let p = join(this.dir, this.dist, 'bundles', 'pages', paths.join('/'))
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.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册