From e033010841cb4617353bfe2f936340a88185f18d Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 13 Nov 2018 13:21:19 +0200 Subject: [PATCH] Rename manifest.json to thelounge.webmanifest This makes express serve it with correct content-type of application/manifest+json Refs: - https://w3c.github.io/manifest/#media-type-registration - https://webhint.io/docs/user-guide/hints/hint-manifest-file-extension/ --- client/index.html.tpl | 2 +- client/{manifest.json => thelounge.webmanifest} | 0 src/command-line/index.js | 13 ------------- src/helper.js | 12 ++++++++++-- test/server.js | 3 ++- 5 files changed, 13 insertions(+), 17 deletions(-) rename client/{manifest.json => thelounge.webmanifest} (100%) diff --git a/client/index.html.tpl b/client/index.html.tpl index d8fecef2..3452db76 100644 --- a/client/index.html.tpl +++ b/client/index.html.tpl @@ -24,7 +24,7 @@ - + diff --git a/client/manifest.json b/client/thelounge.webmanifest similarity index 100% rename from client/manifest.json rename to client/thelounge.webmanifest diff --git a/src/command-line/index.js b/src/command-line/index.js index a6206332..107a1450 100644 --- a/src/command-line/index.js +++ b/src/command-line/index.js @@ -5,7 +5,6 @@ const log = require("../log"); const fs = require("fs"); const path = require("path"); const program = require("commander"); -const colors = require("chalk"); const Helper = require("../helper"); const Utils = require("./utils"); @@ -20,18 +19,6 @@ program.version(Helper.getVersion(), "-v, --version") // Parse options from `argv` returning `argv` void of these options. const argvWithoutOptions = program.parseOptions(process.argv); -// Check if the app was built before calling setHome as it wants to load manifest.json from the public folder -if (!fs.existsSync(path.join( - __dirname, - "..", - "..", - "public", - "manifest.json" -))) { - log.error(`The client application was not built. Run ${colors.bold("NODE_ENV=production yarn build")} to resolve this.`); - process.exit(1); -} - Helper.setHome(process.env.THELOUNGE_HOME || Utils.defaultHome()); // Check config file owner and warn if we're running under a different user diff --git a/src/helper.js b/src/helper.js index a549b333..5874db7a 100644 --- a/src/helper.js +++ b/src/helper.js @@ -117,8 +117,16 @@ function setHome(newPath) { log.warn(`${colors.bold("displayNetwork")} and ${colors.bold("lockNetwork")} are false, setting ${colors.bold("lockNetwork")} to true.`); } - // Load theme color from manifest.json - const manifest = require("../public/manifest.json"); + const manifestPath = path.resolve(path.join(__dirname, "..", "public", "thelounge.webmanifest")); + + // Check if manifest exists, if not, the app most likely was not built + if (!fs.existsSync(manifestPath)) { + log.error(`The client application was not built. Run ${colors.bold("NODE_ENV=production yarn build")} to resolve this.`); + process.exit(1); + } + + // Load theme color from the web manifest + const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8")); this.config.themeColor = manifest.theme_color; // TODO: Remove in future release diff --git a/test/server.js b/test/server.js index ebe32fb8..c5cd026f 100644 --- a/test/server.js +++ b/test/server.js @@ -41,11 +41,12 @@ describe("Server", function() { }); it("should serve static content correctly", (done) => { - request(webURL + "manifest.json", (error, response, body) => { + request(webURL + "thelounge.webmanifest", (error, response, body) => { expect(error).to.be.null; body = JSON.parse(body); expect(body.name).to.equal("The Lounge"); + expect(response.headers["content-type"]).to.equal("application/manifest+json"); done(); });