From 006bacfef06f405b804d82f0e53952b3d0262f9e Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 8 Jun 2020 19:07:13 +0200 Subject: [PATCH] :bug: Fix worker uri handling on release builds. --- frontend/gulpfile.js | 31 +++++++++++------------ frontend/src/uxbox/config.cljs | 4 ++- frontend/src/uxbox/main/worker.cljs | 9 ++----- frontend/src/uxbox/worker.cljs | 8 ------ frontend/src/uxbox/worker/impl.cljs | 4 --- frontend/src/uxbox/worker/thumbnails.cljs | 3 +-- 6 files changed, 21 insertions(+), 38 deletions(-) diff --git a/frontend/gulpfile.js b/frontend/gulpfile.js index 9b09067ae..26ed55c40 100644 --- a/frontend/gulpfile.js +++ b/frontend/gulpfile.js @@ -110,7 +110,6 @@ function readLocales() { function readConfig(data) { const googleClientID = process.env.UXBOX_GOOGLE_CLIENT_ID; - const publicURI = process.env.UXBOX_PUBLIC_URI; const demoWarn = process.env.UXBOX_DEMO_WARNING; const deployDate = process.env.UXBOX_DEPLOY_DATE; const deployCommit = process.env.UXBOX_DEPLOY_COMMIT; @@ -123,10 +122,6 @@ function readConfig(data) { cfg.googleClientID = googleClientID; } - if (publicURI !== undefined) { - cfg.publicURI = publicURI; - } - if (deployDate !== undefined) { cfg.deployDate = deployDate; } @@ -140,26 +135,24 @@ function readConfig(data) { return JSON.stringify(cfg); } -const defaultManifest = { - "main": "/js/main.js", - "shared": "/js/shared.js", - "worker": "js/worker.js" -}; - -function readManifest() { +function readManifest(publicURI) { try { const path = __dirname + "/resources/public/js/manifest.json"; const content = JSON.parse(fs.readFileSync(path, {encoding: "utf8"})); const index = {}; for (let item of content) { - index[item.name] = "/js/" + item["output-name"]; + index[item.name] = publicURI + "/js/" + item["output-name"]; }; return index; } catch (e) { console.error("Error on reading manifest, using default."); - return defaultManifest; + return { + "main": publicURI + "/js/main.js", + "shared": publicURI + "/js/shared.js", + "worker": publicURI + "/js/worker.js" + }; } } @@ -182,12 +175,18 @@ function templatePipeline(options) { const output = options.output; const ts = Math.floor(new Date()); + const publicURI = process.env.UXBOX_PUBLIC_URI || "http://localhost:3449"; const th = process.env.UXBOX_THEME || "default"; + const themes = ["default"]; const locales = readLocales(); - const manifest = readManifest(); - const config = readConfig({themes, manifest}); + const manifest = readManifest(publicURI); + + const config = readConfig({ + workerURI: manifest.worker, + publicURI: publicURI + }); const tmpl = mustache({ ts: ts, diff --git a/frontend/src/uxbox/config.cljs b/frontend/src/uxbox/config.cljs index 9bf89b08a..dc0e70614 100644 --- a/frontend/src/uxbox/config.cljs +++ b/frontend/src/uxbox/config.cljs @@ -12,11 +12,13 @@ (this-as global (let [config (obj/get global "uxboxConfig") - puri (obj/get config "publicURI" "http://localhost:3449/") + puri (obj/get config "publicURI") + wuri (obj/get config "workerURI") gcid (obj/get config "googleClientID" true) warn (obj/get config "demoWarning" true)] (def default-language "en") (def demo-warning warn) (def google-client-id gcid) + (def worker-uri wuri) (def public-uri puri) (def default-theme "default"))) diff --git a/frontend/src/uxbox/main/worker.cljs b/frontend/src/uxbox/main/worker.cljs index e3f951da8..ab947058d 100644 --- a/frontend/src/uxbox/main/worker.cljs +++ b/frontend/src/uxbox/main/worker.cljs @@ -12,9 +12,7 @@ [cljs.spec.alpha :as s] [uxbox.config :as cfg] [uxbox.common.spec :as us] - [uxbox.util.worker :as uw]) - (:import - goog.Uri)) + [uxbox.util.worker :as uw])) (defn on-error [instance error] @@ -22,10 +20,7 @@ (defonce instance (when (not= *target* "nodejs") - (let [uri (Uri. cfg/public-uri)] - (.setPath uri "/js/worker.js") - (.setParameterValue uri "publicURI" cfg/public-uri) - (uw/init (.toString uri) on-error)))) + (uw/init cfg/worker-uri on-error))) (defn ask! [message] diff --git a/frontend/src/uxbox/worker.cljs b/frontend/src/uxbox/worker.cljs index 8726a6168..ddc819214 100644 --- a/frontend/src/uxbox/worker.cljs +++ b/frontend/src/uxbox/worker.cljs @@ -25,14 +25,6 @@ [uxbox.util.worker :as w]) (:import goog.Uri)) -;; --- Initialization - -(this-as global - (let [location (obj/get global "location") - uri (Uri. (obj/get location "href")) - puri (.getParameterValue uri "publicURI")] - (swap! impl/config assoc :public-uri puri))) - ;; --- Messages Handling (s/def ::cmd keyword?) diff --git a/frontend/src/uxbox/worker/impl.cljs b/frontend/src/uxbox/worker/impl.cljs index 8004bb4fc..83c4f7621 100644 --- a/frontend/src/uxbox/worker/impl.cljs +++ b/frontend/src/uxbox/worker/impl.cljs @@ -11,10 +11,6 @@ (enable-console-print!) -;; --- Config - -(defonce config (l/atom {})) - ;; --- Handler (defmulti handler :cmd) diff --git a/frontend/src/uxbox/worker/thumbnails.cljs b/frontend/src/uxbox/worker/thumbnails.cljs index 43d7da701..0d1e61c18 100644 --- a/frontend/src/uxbox/worker/thumbnails.cljs +++ b/frontend/src/uxbox/worker/thumbnails.cljs @@ -33,8 +33,7 @@ (defn- request-page [id] - (let [uri (get @impl/config :public-uri "http://localhost:3449/") - uri (str uri "/api/w/query/page")] + (let [uri "/api/w/query/page"] (p/create (fn [resolve reject] (->> (http/send! {:uri uri