From 33d82287be436553bc83a39fb1a1baaa5708cd07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Sat, 13 Jan 2018 19:46:59 -0500 Subject: [PATCH] Do not statically serve the index template prior to rendering it Without this, going to `https://thelounge.example.com/index.html` would return the raw file. This now excludes it from the `public` folder so it cannot be rendered as is. Renaming the file is for good measure, to indicate that this HTML file must be templated. Because it is a straight rename with no modification, rebasing PRs on it should not be to painful, as git re-applies changes on renamed files. --- .npmignore | 1 + client/{index.html => index.html.tpl} | 0 src/server.js | 2 +- test/tests/build.js | 5 +++-- webpack.config.js | 3 ++- 5 files changed, 7 insertions(+), 4 deletions(-) rename client/{index.html => index.html.tpl} (100%) diff --git a/.npmignore b/.npmignore index 8eacd35d..55850e0a 100644 --- a/.npmignore +++ b/.npmignore @@ -11,6 +11,7 @@ client/** !client/js/libs/handlebars/ircmessageparser/findLinks.js !client/js/libs/handlebars/ircmessageparser/cleanIrcMessage.js +!client/index.html.tpl public/js/bundle.vendor.js.map coverage/ diff --git a/client/index.html b/client/index.html.tpl similarity index 100% rename from client/index.html rename to client/index.html.tpl diff --git a/src/server.js b/src/server.js index 09382047..ad13ce5b 100644 --- a/src/server.js +++ b/src/server.js @@ -251,7 +251,7 @@ function index(req, res, next) { res.setHeader("Content-Security-Policy", policies.join("; ")); res.setHeader("Referrer-Policy", "no-referrer"); - return fs.readFile(path.join(__dirname, "..", "public", "index.html"), "utf-8", (err, file) => { + return fs.readFile(path.join(__dirname, "..", "client", "index.html.tpl"), "utf-8", (err, file) => { if (err) { throw err; } diff --git a/test/tests/build.js b/test/tests/build.js index e5b2b1da..3329ed22 100644 --- a/test/tests/build.js +++ b/test/tests/build.js @@ -12,8 +12,9 @@ describe("public folder", function() { expect(fs.existsSync(path.join(publicFolder, "fonts", "fontawesome-webfont.woff2"))).to.be.true; }); - it("index.html is copied", function() { - expect(fs.existsSync(path.join(publicFolder, "index.html"))).to.be.true; + it("index HTML file is not copied", function() { + expect(fs.existsSync(path.join(publicFolder, "index.html"))).to.be.false; + expect(fs.existsSync(path.join(publicFolder, "index.html.tpl"))).to.be.false; }); it("javascript files are built", function() { diff --git a/webpack.config.js b/webpack.config.js index e30258c9..2b0948f9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -70,9 +70,10 @@ const config = { from: "./client/js/loading-error-handlers.js", to: "js/[name].[ext]", }, - { // TODO: Build index.html with handlebars + { from: "./client/*", to: "[name].[ext]", + ignore: "index.html.tpl", }, { from: "./client/audio/*",