From 6a6118e136776ce27c2e7456dd517df083dba493 Mon Sep 17 00:00:00 2001 From: Jason Papakostas Date: Tue, 24 May 2016 19:08:09 -0500 Subject: [PATCH] serve config.json statically instead of bundling it issue #1344 --- package.json | 1 + src/vector/index.js | 26 +++++++++++++++++++++++--- vector/config.json | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) create mode 120000 vector/config.json diff --git a/package.json b/package.json index c2400cedf..0da702490 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ }, "dependencies": { "babel-polyfill": "^6.5.0", + "browser-request": "^0.3.3", "classnames": "^2.1.2", "extract-text-webpack-plugin": "^0.9.1", "filesize": "^3.1.2", diff --git a/src/vector/index.js b/src/vector/index.js index db353c250..af48b4b07 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -40,8 +40,9 @@ var ReactDOM = require("react-dom"); var sdk = require("matrix-react-sdk"); sdk.loadSkin(require('../component-index')); var VectorConferenceHandler = require('../VectorConferenceHandler'); -var configJson = require("../../config.json"); var UpdateChecker = require("./updater"); +var q = require('q'); +var request = require('browser-request'); var qs = require("querystring"); @@ -181,7 +182,24 @@ window.onload = function() { } } -function loadApp() { +function getConfig() { + let deferred = q.defer(); + + request( + { method: "GET", url: "config.json", json: true }, + (err, response, body) => { + if (err || response.status < 200 || response.status >= 300) { + throw "failed to load config.json"; + } + + deferred.resolve(body); + } + ); + + return deferred.promise; +} + +async function loadApp() { if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) { if (confirm("Vector works much better on iOS as an app. Switch to the app?")) { window.location = "https://itunes.apple.com/us/app/vector.im/id1083446067"; @@ -194,7 +212,9 @@ function loadApp() { return; } } - + + let configJson = await getConfig(); + console.log("Vector starting at "+window.location); if (validBrowser) { var MatrixChat = sdk.getComponent('structures.MatrixChat'); diff --git a/vector/config.json b/vector/config.json new file mode 120000 index 000000000..28e148537 --- /dev/null +++ b/vector/config.json @@ -0,0 +1 @@ +../config.json \ No newline at end of file