An Adventure in Serverless ClojureScript

18
An Adventure in Serverless ClojureScript Norman Richards

Transcript of An Adventure in Serverless ClojureScript

Page 1: An Adventure in Serverless ClojureScript

An Adventure inServerless ClojureScript

Norman Richards

Page 2: An Adventure in Serverless ClojureScript

Original goal:Get out of my comfort zone and do something new with Clojure

Page 3: An Adventure in Serverless ClojureScript

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

http://gateis.red/My project:

Page 5: An Adventure in Serverless ClojureScript
Page 6: An Adventure in Serverless ClojureScript
Page 7: An Adventure in Serverless ClojureScript
Page 8: An Adventure in Serverless ClojureScript

Let's make a ClojureScript app

Page 9: An Adventure in Serverless ClojureScript

$ 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

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

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

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

Let's deploy the app

Page 14: An Adventure in Serverless ClojureScript

$ lein do clean, cljsbuild once min

resources/public ├── css │   └── style.css ├── index.html └── js └── compiled └── yourprojectname.js

Page 15: An Adventure in Serverless ClojureScript

Upload to S3 bucket

Page 16: An Adventure in Serverless ClojureScript

Configure S3 for static website

http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html

Page 17: An Adventure in Serverless ClojureScript

Configure DNS

Page 18: An Adventure in Serverless ClojureScript