From 3d1c4ccc133e4387bd6ba63b53219e6d9a84dcec Mon Sep 17 00:00:00 2001 From: MICHAEL JACKSON Date: Tue, 5 Dec 2017 11:56:54 -0800 Subject: [PATCH] Serve JS files as utf-8 See https://github.com/babel/babel/issues/6976 --- server/middleware/serveFile.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/middleware/serveFile.js b/server/middleware/serveFile.js index e305b98..a6eb1bc 100644 --- a/server/middleware/serveFile.js +++ b/server/middleware/serveFile.js @@ -78,7 +78,7 @@ function serveFile(req, res, next) { // Cache modules for 1 year. res .set({ - "Content-Type": contentType, + "Content-Type": `${contentType}; charset=utf-8`, "Content-Length": Buffer.byteLength(code), "Cache-Control": "public, max-age=31536000", "Cache-Tag": "file,js-file,js-module" @@ -91,9 +91,10 @@ function serveFile(req, res, next) { const tags = ["file"] const ext = path.extname(req.filename).substr(1) - if (ext) tags.push(`${ext}-file`) + if (contentType === "application/javascript") contentType += "; charset=utf-8" + // Cache files for 1 year. res.set({ "Content-Type": contentType,