-
Notifications
You must be signed in to change notification settings - Fork 2
/
core.clj
65 lines (55 loc) · 1.71 KB
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(ns artifact.core
(:use [ring.adapter.jetty :only (run-jetty)]
[ring.middleware.params]
[ring.middleware.multipart-params]
[artifact.game :only (new-game)]
[artifact.state :only (*game*)]
[clojure.data.json :only (read-json)]
compojure.core
artifact.ui
artifact.api
artifact.logging
artifact.tuplestore)
(:require [compojure.handler :as handler]
[compojure.route :as route])
(:gen-class)
(:refer-clojure :exclude [time]))
(dosync (ref-set *game* (new-game)))
(defroutes api-routes
;; TODO: extract token validation into middleware?
(GET "/api" [token] (api-get token))
(POST "/api" [token]
(fn [req]
(let [body (slurp (:body req))]
(debug "Body is:" body)
(debug "token is:" token)
(api-post token (read-json body false))))))
(defroutes test-routes
(POST "/test" [token] "test")
;;(GET "/professor-board" [] (professor-board-page))
)
(defroutes page-routes
(GET "/" [] (index))
(POST "/join" [name] (join-page name))
(GET "/game/:token" [token] (game-page token)))
(defroutes default-routes
(route/resources "/")
(route/not-found "Page not found"))
(defroutes all-routes
api-routes
test-routes
(handler/site page-routes)
default-routes)
(def app (wrap-params all-routes))
(defn -main [& args]
(let [port (Integer/parseInt (get (System/getenv) "PORT" "8080"))]
(run-jetty app {:port port})))
(let [server (atom nil)
set-server #(reset! server %)]
(defn debug-start []
(future (run-jetty (var app) {:port 8080 :configurator set-server})))
(defn debug-stop []
(.stop @server)))
(defn reset-game []
(dosync
(ref-set *game* (new-game))))