Commit 40d926d7 authored by Tomas Roos's avatar Tomas Roos Committed by Tim Neutkens

Expose main.js.map (#3969)

parent ae07cbae
...@@ -158,21 +158,21 @@ export default class Server { ...@@ -158,21 +158,21 @@ export default class Server {
await this.serveStatic(req, res, p) 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) 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') const p = join(this.dir, this.dist, 'manifest.js')
await this.serveStatic(req, res, p) 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) { if (this.dev) {
this.handleBuildHash('main.js', params.hash, res) this.handleBuildId(params.buildId, res)
const p = join(this.dir, this.dist, 'main.js') const p = join(this.dir, this.dist, 'main.js')
await this.serveStatic(req, res, p) await this.serveStatic(req, res, p)
} else { } else {
const buildId = params.hash const buildId = params.buildId
if (!this.handleBuildId(buildId, res)) { if (!this.handleBuildId(buildId, res)) {
const error = new Error('INVALID_BUILD_ID') const error = new Error('INVALID_BUILD_ID')
const customFields = { buildIdMismatched: true } const customFields = { buildIdMismatched: true }
...@@ -185,6 +185,22 @@ export default class Server { ...@@ -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) => { '/_next/:buildId/page/:path*.js.map': async (req, res, params) => {
const paths = params.path || [''] const paths = params.path || ['']
const page = `/${paths.join('/')}` const page = `/${paths.join('/')}`
...@@ -452,16 +468,6 @@ export default class Server { ...@@ -452,16 +468,6 @@ export default class Server {
return Array.from(errors.values())[0][0] 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) { send404 (res) {
res.statusCode = 404 res.statusCode = 404
res.end('404 - Not Found') res.end('404 - Not Found')
......
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