From 25230f2e9d1e2aedcb1663ce731986da275acd4f Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 18 May 2017 16:30:28 -0600 Subject: [PATCH] added fix for chrome + content type negotiation --- app.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index 868ceee4c..16840f965 100644 --- a/app.js +++ b/app.js @@ -43,8 +43,15 @@ if (process.env.NODE_ENV === 'production') { app.get('*.js', (req, res, next) => { const accept = accepts(req); if (accept.encoding(['gzip']) === 'gzip') { - req.url = `${req.url}.gz`; + + // Adjsut the headers on the request by adding a content type header + // because express won't be able to detect the mime-type with the .gz + // extension and we need to decalre support for the gzip encoding. + res.set('Content-Type', 'application/javascript'); res.set('Content-Encoding', 'gzip'); + + // Rewrite the url so that the gzip version will be served instead. + req.url = `${req.url}.gz`; } next();