Skip to content

Commit

Permalink
HYPERFIDDLE_ELECTRIC_..._VERSION has been renamed
Browse files Browse the repository at this point in the history
Electric now only defines ELECTRIC_USER_VERSION.
  • Loading branch information
ggeoffrey committed Jan 10, 2024
1 parent 0f1a21b commit 68e1c0c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ COPY --from=build /app/app.jar app.jar
EXPOSE 8080
ARG VERSION
ENV VERSION=$VERSION
CMD java -DHYPERFIDDLE_ELECTRIC_SERVER_VERSION=$VERSION -jar app.jar
CMD java -DELECTRIC_USER_VERSION=$VERSION -jar app.jar
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ ClojureScript optimized build, Dockerfile, Uberjar, Github actions CD to fly.io
```
HYPERFIDDLE_ELECTRIC_APP_VERSION=`git describe --tags --long --always --dirty`
clojure -X:build uberjar :jar-name "app.jar" :version '"'$HYPERFIDDLE_ELECTRIC_APP_VERSION'"'
java -DHYPERFIDDLE_ELECTRIC_SERVER_VERSION=$HYPERFIDDLE_ELECTRIC_APP_VERSION -jar app.jar
java -DELECTRIC_USER_VERSION=$HYPERFIDDLE_ELECTRIC_APP_VERSION -jar app.jar
```

```
Expand Down
4 changes: 2 additions & 2 deletions src-build/build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ on startup)"
(shadow-api/release :prod {:debug debug,
:verbose verbose,
:config-merge [{:compiler-options {:optimizations (if optimize :advanced :simple)}
:closure-defines {'hyperfiddle.electric-client/VERSION version}}]})
:closure-defines {'hyperfiddle.electric-client/ELECTRIC_USER_VERSION version}}]})
(shadow-server/stop!))

(defn uberjar [{:keys [jar-name version optimize debug verbose]
Expand Down Expand Up @@ -59,4 +59,4 @@ on startup)"
:basis basis
:main 'prod}))

(defn noop [_]) ; run to preload mvn deps
(defn noop [_]) ; run to preload mvn deps
4 changes: 2 additions & 2 deletions src/app/electric_server_java11_jetty10.clj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,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 ^:const 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 @@ -77,7 +77,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/app/electric_server_java8_jetty9.clj
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,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
4 changes: 2 additions & 2 deletions src/prod.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
{:host "0.0.0.0", :port 8080, :resources-path "public"})

(defn -main [& args] ; run with `clj -M -m prod`
(when (clojure.string/blank? (System/getProperty "HYPERFIDDLE_ELECTRIC_SERVER_VERSION"))
(throw (ex-info "HYPERFIDDLE_ELECTRIC_SERVER_VERSION jvm property must be set in prod" {})))
(when (clojure.string/blank? (System/getProperty "ELECTRIC_USER_VERSION"))
(throw (ex-info "ELECTRIC_USER_VERSION jvm property must be set in prod" {})))
(app.electric-server-java8-jetty9/start-server! boot/with-ring-request electric-server-config))

; On CLJS side we reuse src/user.cljs for prod entrypoint

0 comments on commit 68e1c0c

Please sign in to comment.