Skip to content

Commit

Permalink
Bump Electric dependency and apply necessary changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ggeoffrey committed Jan 10, 2024
1 parent 1250334 commit ff3561d
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion src-build/build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions src/electric_server_java11_jetty10.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/electric_server_java8_jetty9.clj
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@
;; 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.
An electric client is allowed to connect if its version matches the server's version, or if the server doesn't have a version set (dev mode).
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)
Expand Down
5 changes: 4 additions & 1 deletion src/prod.clj
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/user.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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! []
Expand Down
2 changes: 1 addition & 1 deletion vendors/electric
Submodule electric updated 120 files

0 comments on commit ff3561d

Please sign in to comment.