An Adventure in Serverless ClojureScript
-
Upload
norman-richards -
Category
Technology
-
view
184 -
download
0
Transcript of An Adventure in Serverless ClojureScript
An Adventure inServerless ClojureScript
Norman Richards
Original goal:Get out of my comfort zone and do something new with Clojure
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)
http://gateis.red/My project:
Let's make a ClojureScript app
$ 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
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"]]
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 -
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!)
Let's deploy the app
$ lein do clean, cljsbuild once min
resources/public ├── css │ └── style.css ├── index.html └── js └── compiled └── yourprojectname.js
Upload to S3 bucket
Configure S3 for static website
http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html
Configure DNS