1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Expose main.js.map (#3969)

This commit is contained in:
Tomas Roos 2018-03-08 11:49:25 +01:00 committed by Tim Neutkens
parent ae07cbae09
commit 40d926d794

View file

@ -158,21 +158,21 @@ export default class Server {
await this.serveStatic(req, res, p)
},
'/_next/:hash/manifest.js': async (req, res, params) => {
'/_next/:buildId/manifest.js': async (req, res, params) => {
if (!this.dev) return this.send404(res)
this.handleBuildHash('manifest.js', params.hash, res)
this.handleBuildId(params.buildId, res)
const p = join(this.dir, this.dist, 'manifest.js')
await this.serveStatic(req, res, p)
},
'/_next/:hash/main.js': async (req, res, params) => {
'/_next/:buildId/main.js': async (req, res, params) => {
if (this.dev) {
this.handleBuildHash('main.js', params.hash, res)
this.handleBuildId(params.buildId, res)
const p = join(this.dir, this.dist, 'main.js')
await this.serveStatic(req, res, p)
} else {
const buildId = params.hash
const buildId = params.buildId
if (!this.handleBuildId(buildId, res)) {
const error = new Error('INVALID_BUILD_ID')
const customFields = { buildIdMismatched: true }
@ -185,6 +185,22 @@ export default class Server {
}
},
'/_next/:buildId/main.js.map': async (req, res, params) => {
if (this.dev) {
this.handleBuildId(params.buildId, res)
const p = join(this.dir, this.dist, 'main.js.map')
await this.serveStatic(req, res, p)
} else {
const buildId = params.buildId
if (!this.handleBuildId(buildId, res)) {
return await this.render404(req, res)
}
const p = join(this.dir, this.dist, 'main.js.map')
await this.serveStatic(req, res, p)
}
},
'/_next/:buildId/page/:path*.js.map': async (req, res, params) => {
const paths = params.path || ['']
const page = `/${paths.join('/')}`
@ -452,16 +468,6 @@ export default class Server {
return Array.from(errors.values())[0][0]
}
handleBuildHash (filename, hash, res) {
if (this.dev) {
res.setHeader('Cache-Control', 'no-store, must-revalidate')
return true
}
res.setHeader('Cache-Control', 'max-age=31536000, immutable')
return true
}
send404 (res) {
res.statusCode = 404
res.end('404 - Not Found')