an adventure in serverless clojurescript
TRANSCRIPT
![Page 1: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/1.jpg)
An Adventure inServerless ClojureScript
Norman Richards
![Page 2: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/2.jpg)
Original goal:Get out of my comfort zone and do something new with Clojure
![Page 3: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/3.jpg)
The original stack
• Figwheel dev environment (how will I deploy this? will )
• Quiescent with Sablono (instead of Om)
• cljs-ajax (not aware of other choices here)
• Bootstrap 4 (why go beta when you go alpha)
![Page 4: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/4.jpg)
http://gateis.red/My project:
![Page 5: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/5.jpg)
![Page 6: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/6.jpg)
![Page 7: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/7.jpg)
![Page 8: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/8.jpg)
Let's make a ClojureScript app
![Page 9: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/9.jpg)
$ lein new figwheel yourprojectname
Generating fresh 'lein new' figwheel project.
Change into your 'yourprojectname' directory and run 'lein figwheel' Wait for it to finish compiling Then open 'http://localhost:3449/index.html' in your browser
![Page 10: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/10.jpg)
project.clj
:jvm-opts ["-XX:MaxPermSize=128m" "-server"]
:dependencies [[org.clojure/clojure "1.8.0"] [org.clojure/clojurescript "1.8.51"] [quiescent "0.3.2"] [sablono "0.7.2"]]
![Page 11: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/11.jpg)
Start figwheel
user> (fig-start) Figwheel: Starting server at http://0.0.0.0:3449 ... user> (cljs-repl) ... cljs.user>
$ lein figwheel ... Prompt will show when Figwheel connects to your application To quit, type: :cljs/quit cljs.user=>
- or from CIDER -
![Page 12: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/12.jpg)
A trivial app(defonce app-state (atom {:count 0}))
(defn bump-counter [] (swap! app-state update-in [:count] inc))
(q/defcomponent Counter [state] (h/html [:div [:h1 "The counter is: " (:count state)] [:button {:onClick bump-counter} "Add one"]]))
(defn render! [] (q/render (Counter @app-state) (.getElementById js/document "app")) (js/window.requestAnimationFrame render!))
(render!)
![Page 13: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/13.jpg)
Let's deploy the app
![Page 14: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/14.jpg)
$ lein do clean, cljsbuild once min
resources/public ├── css │ └── style.css ├── index.html └── js └── compiled └── yourprojectname.js
![Page 15: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/15.jpg)
Upload to S3 bucket
![Page 16: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/16.jpg)
Configure S3 for static website
http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html
![Page 17: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/17.jpg)
Configure DNS
![Page 18: An Adventure in Serverless ClojureScript](https://reader031.vdocuments.us/reader031/viewer/2022022413/58ed0dc91a28aba0548b45e3/html5/thumbnails/18.jpg)