So turns out it’s relatively straightforward to sidestep this problem if your interest is deploying a clojurescript app to connect to the ion.
Just serve it from within, word of warning, this isn’t the best way to do it, I’d preferably be sticking my cljs app in say an s3 bucket/cloudfront serving it from there, but for now this will serve.
I might come back in a month or two to improve the situation here.
There is however a few stumbling blocks to this master plan.
- Serving
index.html
with executable js:
You need your:resource-path
set as well as adjusting:content-security-policy-settings
.
In my case that’s:
(ns ion.service
(:require [ring.util.response :as r]
[io.pedestal.http :as http]
[io.pedestal.http.route :as route]
[io.pedestal.http.body-params :as body-params]
[io.pedestal.ions :as provider]))
(defn home
[request]
(r/content-type
(r/resource-response "public/index.html")
"text/html"))
(def common-interceptors [(body-params/body-params) http/json-body])
(def routes #{["/" :get (conj common-interceptors `home)]
["/about" :get (conj common-interceptors `about)]})
(defn accept-all [origin] true)
(def service {::http/routes routes
::http/allowed-origins accept-all
::http/resource-path "/public"
::http/secure-headers {:content-security-policy-settings {:script-src "* 'unsafe-inline'"}}
::http/chain-provider provider/ion-provider})
- In your clojurescript project add
cljsbuild
configs to stick stuff inpublic
, I’m using figwheel with re-frame, but this should work with whatever you want!
;;; Stick this inside the [:cljsbuild :builds] vector
;;; NOTE: <backend ion project> can be a relative path!
{:id "iondev"
:source-paths ["src/cljs"]
:figwheel {:on-jsload "frontend-client.core/mount-root"}
:compiler {:main frontend-client.core
:output-to "<backend ion project>/resources/public/js/compiled/app.js"
:output-dir "<backend ion project>/resources/public/js/compiled/out"
:asset-path "js/compiled/out"
:source-map-timestamp true
:preloads [devtools.preload
day8.re-frame-10x.preload]
:closure-defines {"re_frame.trace.trace_enabled_QMARK_" true
"day8.re_frame.tracing.trace_enabled_QMARK_" true}
:external-config {:devtools/config {:features-to-install :all}}}}
{:id "ionmin"
:source-paths ["src/cljs"]
:compiler {:main frontend-client.core
:output-to "<backend ion project>/resources/public/js/compiled/app.js"
:output-dir "<backend ion project>/resources/public/js/compiled/min"
:optimizations :advanced
:closure-defines {goog.DEBUG false}
:pretty-print false}}
;;; For completeness I add the line below to the `:clean-targets` vector
"<backend ion project>/resources/public/js/compiled/"
So in my case I can now do:
;; Terminal 1: (repl)
clojure -Adev:log:jetty:rebel
;; Terminal 2: (proxy)
bash datomic-socks-proxy <ion stack name>
;; Terminal 3: (deploy)
clojure -Adev -m datomic.ion.dev '{:op :push :uname "app-test"}'
clojure -Adev -m datomic.ion.dev '{:op :deploy, :group <ion stack name>, :uname "app-test"}'
;;; Then copy/paste result of :status-command to see when it's done
;; Terminal 4: (fig) <- This is the terminal sitting in the frontend-client project
;;; dev
lein figwheel iondev
;;; or do the below before using Terminal 3 to deploy the generated compiled code
lein clean
lein cljsbuild once ionmin
There, that’s basically where I’m at present, hopefully I don’t encounter any more issues =)…