Created
April 10, 2016 20:16
-
-
Save micha/5f703c1f9580bd8c0d7e014627318634 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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