Skip to content

Instantly share code, notes, and snippets.

@micha
Created April 10, 2016 20:16
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 micha/5f703c1f9580bd8c0d7e014627318634 to your computer and use it in GitHub Desktop.
Save micha/5f703c1f9580bd8c0d7e014627318634 to your computer and use it in GitHub Desktop.
(ns app-boilerplate.server
(:require [aleph.http :as http]
[clojure.java.io :as io]
[mount.core :as mount :refer [defstate]]
[hiccup.page :refer [html5 include-js]]))
(def index
(html5
[:html
[:head {:lang "en"}
[:meta {:name "viewport"
:content "width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"}]
[:meta {:charset "UTF-8"}]
[:title "title"]]
[:body
[:div#app
[:h1 "Waiting for cljs to compile..."]]
(include-js "main.js")]]))
(defn handler [{:keys [uri] :as req}]
(if (= uri "/")
{:status 200
:headers {"content-type" "text/html"}
:body index}
{:status 200
:headers {"content-type" "text/javascript"}
:body (slurp (io/resource (subs uri 1)))}))
(defstate server
:start (http/start-server #'handler {:port 3000})
:stop (.close server))
(defn start [] (mount/start))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment