1
0
Fork 0
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:
Tim Neutkens 2018-01-13 08:34:48 +01:00
parent 95fe683c58
commit 963695820f
2 changed files with 9 additions and 10 deletions

View file

@ -1,4 +1,4 @@
/* 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}`

View file

@ -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.