From ff3561d88a8c03005e11335dcf45e40f6d3efa2f Mon Sep 17 00:00:00 2001 From: Geoffrey Gaillard Date: Wed, 10 Jan 2024 17:18:17 +0100 Subject: [PATCH] Bump Electric dependency and apply necessary changes --- Dockerfile | 2 +- deps.edn | 2 +- src-build/build.clj | 2 +- src/electric_server_java11_jetty10.clj | 4 ++-- src/electric_server_java8_jetty9.clj | 4 ++-- src/prod.clj | 5 ++++- src/user.clj | 2 +- src/user.cljs | 2 +- vendors/electric | 2 +- 9 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 14ae262..ee18f65 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,4 +38,4 @@ ARG VERSION RUN clojure -T:build build-client :verbose true :version '"'$VERSION'"' ENV VERSION=$VERSION -CMD clj -J-DHYPERFIDDLE_ELECTRIC_SERVER_VERSION=$VERSION -M -m prod +CMD clj -J-DELECTRIC_USER_VERSION=$VERSION -M -m prod diff --git a/deps.edn b/deps.edn index 1b39663..5c2f41d 100644 --- a/deps.edn +++ b/deps.edn @@ -1,7 +1,7 @@ {:paths ["src" "resources"] :deps {com.datomic/dev-local {:mvn/version "1.0.243"} com.google.guava/guava {:mvn/version "31.1-jre"} ; fix conflict - datomic cloud & shadow - com.hyperfiddle/electric {:mvn/version "v2-alpha-428-g22937f75"} + com.hyperfiddle/electric {:mvn/version "v2-alpha-536-g0c582f78"} com.hyperfiddle/rcf {:mvn/version "20220926-202227"} datascript/datascript {:mvn/version "1.5.2"} com.datomic/peer {:mvn/version "1.0.6735"} diff --git a/src-build/build.clj b/src-build/build.clj index fb75b88..f737a00 100644 --- a/src-build/build.clj +++ b/src-build/build.clj @@ -29,7 +29,7 @@ (when verbose "--verbose") "--config-merge" (pr-str {:compiler-options {:optimizations (if optimize :advanced :simple)} - :closure-defines {'hyperfiddle.electric-client/VERSION version}})] + :closure-defines {'hyperfiddle.electric-client/ELECTRIC_USER_VERSION version}})] (remove nil?))] (apply println "Running:" command) (let [{:keys [exit out err]} (apply sh/sh command)] diff --git a/src/electric_server_java11_jetty10.clj b/src/electric_server_java11_jetty10.clj index 5e7a4fe..5515f50 100644 --- a/src/electric_server_java11_jetty10.clj +++ b/src/electric_server_java11_jetty10.clj @@ -69,7 +69,7 @@ ;; index.html file not found on classpath (next-handler ring-req)))) -(def ^:const VERSION (not-empty (System/getProperty "HYPERFIDDLE_ELECTRIC_SERVER_VERSION"))) ; see Dockerfile +(def VERSION (not-empty (System/getProperty "ELECTRIC_USER_VERSION"))) ; see Dockerfile (defn wrap-reject-stale-client "Intercept websocket UPGRADE request and check if client and server versions matches. @@ -78,7 +78,7 @@ [next-handler] (fn [ring-req] (if (ring/ws-upgrade-request? ring-req) - (let [client-version (get-in ring-req [:query-params "HYPERFIDDLE_ELECTRIC_CLIENT_VERSION"])] + (let [client-version (get-in ring-req [:query-params "ELECTRIC_USER_VERSION"])] (cond (nil? VERSION) (next-handler ring-req) (= client-version VERSION) (next-handler ring-req) diff --git a/src/electric_server_java8_jetty9.clj b/src/electric_server_java8_jetty9.clj index 7c06493..c8a0fb0 100644 --- a/src/electric_server_java8_jetty9.clj +++ b/src/electric_server_java8_jetty9.clj @@ -69,7 +69,7 @@ ;; index.html file not found on classpath (next-handler ring-req)))) -(def ^:const VERSION (not-empty (System/getProperty "HYPERFIDDLE_ELECTRIC_SERVER_VERSION"))) ; see Dockerfile +(def VERSION (not-empty (System/getProperty "ELECTRIC_USER_VERSION"))) ; see Dockerfile (defn wrap-reject-stale-client "Intercept websocket UPGRADE request and check if client and server versions matches. @@ -77,7 +77,7 @@ Otherwise, the client connection is rejected gracefully." [next-handler] (fn [ring-req] - (let [client-version (get-in ring-req [:query-params "HYPERFIDDLE_ELECTRIC_CLIENT_VERSION"])] + (let [client-version (get-in ring-req [:query-params "ELECTRIC_USER_VERSION"])] (cond (nil? VERSION) (next-handler ring-req) (= client-version VERSION) (next-handler ring-req) diff --git a/src/prod.clj b/src/prod.clj index 52c2f53..7ae8fa9 100644 --- a/src/prod.clj +++ b/src/prod.clj @@ -1,12 +1,15 @@ (ns prod (:gen-class) (:require user-main ; in prod, load app into server so it can accept clients + [hyperfiddle.electric :as e] electric-server-java8-jetty9)) (def electric-server-config {:host "0.0.0.0", :port 8080, :resources-path "public"}) (defn -main [& args] ; run with `clj -M -m prod` - (electric-server-java8-jetty9/start-server! electric-server-config)) + (electric-server-java8-jetty9/start-server! + (fn [ring-req] (e/boot-server {} user-main/Main ring-req)) + electric-server-config)) ; On CLJS side we reuse src/user.cljs for prod entrypoint \ No newline at end of file diff --git a/src/user.clj b/src/user.clj index 865e173..e6e14cb 100644 --- a/src/user.clj +++ b/src/user.clj @@ -12,7 +12,7 @@ (def shadow-compile (delay @(requiring-resolve 'shadow.cljs.devtools.api/compile))) (def shadow-release (delay @(requiring-resolve 'shadow.cljs.devtools.api/release))) (def start-electric-server! (delay (partial @(requiring-resolve 'electric-server-java8-jetty9/start-server!) - (fn [ring-req] (e/boot-server user-main/Main ring-req))))) + (fn [ring-req] (e/boot-server {} user-main/Main ring-req))))) (def rcf-enable! (delay @(requiring-resolve 'hyperfiddle.rcf/enable!))) ; Server-side Electric userland code is lazy loaded by the shadow build. diff --git a/src/user.cljs b/src/user.cljs index c7415bb..f099a1e 100644 --- a/src/user.cljs +++ b/src/user.cljs @@ -3,7 +3,7 @@ hyperfiddle.rcf user-main)) -(def electric-main (hyperfiddle.electric/boot-client user-main/Main nil)) +(def electric-main (hyperfiddle.electric/boot-client {} user-main/Main nil)) (defonce reactor nil) (defn ^:dev/after-load ^:export start! [] diff --git a/vendors/electric b/vendors/electric index 574a8f7..0c582f7 160000 --- a/vendors/electric +++ b/vendors/electric @@ -1 +1 @@ -Subproject commit 574a8f73df9ce57ce3c7e194b332f061cbfd7c13 +Subproject commit 0c582f78403f2be1d3ef58df463ca4f58597d22b