🐛 Fix worker uri handling on release builds.

This commit is contained in:
Andrey Antukh 2020-06-08 19:07:13 +02:00
parent a4c7215fa8
commit 006bacfef0
6 changed files with 21 additions and 38 deletions

View file

@ -110,7 +110,6 @@ function readLocales() {
function readConfig(data) { function readConfig(data) {
const googleClientID = process.env.UXBOX_GOOGLE_CLIENT_ID; const googleClientID = process.env.UXBOX_GOOGLE_CLIENT_ID;
const publicURI = process.env.UXBOX_PUBLIC_URI;
const demoWarn = process.env.UXBOX_DEMO_WARNING; const demoWarn = process.env.UXBOX_DEMO_WARNING;
const deployDate = process.env.UXBOX_DEPLOY_DATE; const deployDate = process.env.UXBOX_DEPLOY_DATE;
const deployCommit = process.env.UXBOX_DEPLOY_COMMIT; const deployCommit = process.env.UXBOX_DEPLOY_COMMIT;
@ -123,10 +122,6 @@ function readConfig(data) {
cfg.googleClientID = googleClientID; cfg.googleClientID = googleClientID;
} }
if (publicURI !== undefined) {
cfg.publicURI = publicURI;
}
if (deployDate !== undefined) { if (deployDate !== undefined) {
cfg.deployDate = deployDate; cfg.deployDate = deployDate;
} }
@ -140,26 +135,24 @@ function readConfig(data) {
return JSON.stringify(cfg); return JSON.stringify(cfg);
} }
const defaultManifest = { function readManifest(publicURI) {
"main": "/js/main.js",
"shared": "/js/shared.js",
"worker": "js/worker.js"
};
function readManifest() {
try { try {
const path = __dirname + "/resources/public/js/manifest.json"; const path = __dirname + "/resources/public/js/manifest.json";
const content = JSON.parse(fs.readFileSync(path, {encoding: "utf8"})); const content = JSON.parse(fs.readFileSync(path, {encoding: "utf8"}));
const index = {}; const index = {};
for (let item of content) { for (let item of content) {
index[item.name] = "/js/" + item["output-name"]; index[item.name] = publicURI + "/js/" + item["output-name"];
}; };
return index; return index;
} catch (e) { } catch (e) {
console.error("Error on reading manifest, using default."); 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 output = options.output;
const ts = Math.floor(new Date()); const ts = Math.floor(new Date());
const publicURI = process.env.UXBOX_PUBLIC_URI || "http://localhost:3449";
const th = process.env.UXBOX_THEME || "default"; const th = process.env.UXBOX_THEME || "default";
const themes = ["default"]; const themes = ["default"];
const locales = readLocales(); const locales = readLocales();
const manifest = readManifest(); const manifest = readManifest(publicURI);
const config = readConfig({themes, manifest});
const config = readConfig({
workerURI: manifest.worker,
publicURI: publicURI
});
const tmpl = mustache({ const tmpl = mustache({
ts: ts, ts: ts,

View file

@ -12,11 +12,13 @@
(this-as global (this-as global
(let [config (obj/get global "uxboxConfig") (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) gcid (obj/get config "googleClientID" true)
warn (obj/get config "demoWarning" true)] warn (obj/get config "demoWarning" true)]
(def default-language "en") (def default-language "en")
(def demo-warning warn) (def demo-warning warn)
(def google-client-id gcid) (def google-client-id gcid)
(def worker-uri wuri)
(def public-uri puri) (def public-uri puri)
(def default-theme "default"))) (def default-theme "default")))

View file

@ -12,9 +12,7 @@
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[uxbox.config :as cfg] [uxbox.config :as cfg]
[uxbox.common.spec :as us] [uxbox.common.spec :as us]
[uxbox.util.worker :as uw]) [uxbox.util.worker :as uw]))
(:import
goog.Uri))
(defn on-error (defn on-error
[instance error] [instance error]
@ -22,10 +20,7 @@
(defonce instance (defonce instance
(when (not= *target* "nodejs") (when (not= *target* "nodejs")
(let [uri (Uri. cfg/public-uri)] (uw/init cfg/worker-uri on-error)))
(.setPath uri "/js/worker.js")
(.setParameterValue uri "publicURI" cfg/public-uri)
(uw/init (.toString uri) on-error))))
(defn ask! (defn ask!
[message] [message]

View file

@ -25,14 +25,6 @@
[uxbox.util.worker :as w]) [uxbox.util.worker :as w])
(:import goog.Uri)) (: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 ;; --- Messages Handling
(s/def ::cmd keyword?) (s/def ::cmd keyword?)

View file

@ -11,10 +11,6 @@
(enable-console-print!) (enable-console-print!)
;; --- Config
(defonce config (l/atom {}))
;; --- Handler ;; --- Handler
(defmulti handler :cmd) (defmulti handler :cmd)

View file

@ -33,8 +33,7 @@
(defn- request-page (defn- request-page
[id] [id]
(let [uri (get @impl/config :public-uri "http://localhost:3449/") (let [uri "/api/w/query/page"]
uri (str uri "/api/w/query/page")]
(p/create (p/create
(fn [resolve reject] (fn [resolve reject]
(->> (http/send! {:uri uri (->> (http/send! {:uri uri