Skip to content

Instantly share code, notes, and snippets.

@randylien
Forked from bhauman/core.cljs
Created October 7, 2015 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randylien/b1e337b7677fdd5d919d to your computer and use it in GitHub Desktop.
Save randylien/b1e337b7677fdd5d919d to your computer and use it in GitHub Desktop.
Helpful patterns when developing with ClojureScript Figwheel and Express js
(ns todo-server.core
(:require
[cljs.nodejs :as nodejs]
[figwheel.client :as fw]))
(nodejs/enable-util-print!)
(defonce express (nodejs/require "express"))
(defonce serve-static (nodejs/require "serve-static"))
(defonce http (nodejs/require "http"))
;; app gets redefined on reload
(def app (express))
;; routes get redefined on each reload
(. app (get "/hello"
(fn [req res] (. res (send "Hello world")))))
(. app (use (serve-static "resources/public" #js {:index "index.html"})))
(def -main
(fn []
;; This is the secret sauce. you want to capture a reference to
;; the app function (don't use it directly) this allows it to be redefined on each reload
;; this allows you to change routes and have them hot loaded as you
;; code.
(doto (.createServer http #(app %1 %2))
(.listen 3000))))
(set! *main-cli-fn* -main)
(fw/start { })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment