-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneenaj.clj
36 lines (29 loc) · 1.06 KB
/
neenaj.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
(ns neenaj
(:require [compojure.http.servlet :as servlet])
(:require [compojure.http.routes :as routes])
(:require [compojure.server.jetty :as jetty])
(:import java.io.File)
(:use [compojure.http.helpers])
(:use [neenaj.blog]))
(def static-dir "/home/jwinter/static/")
(defn canonical-path [path]
(.getCanonicalPath (new File path)))
(defn css-js-or-404 [path]
"Serves the canonical path if the file is a .css or .js file in static, otherwise 404"
(let [canon_path (canonical-path (str static-dir "/" path))]
(if (.startsWith canon_path static-dir)
(serve-file static-dir path)
[404 "Not found, man"]
)))
(servlet/defservlet home
"Blog homepage"
(routes/GET "/log/*" (display-entries (fetch-entries)))
(routes/GET "/resume/*" (serve-file static-dir "resume.pdf"))
(routes/GET "/buh-bounce/*" (display-entries (fetch-entries)))
(routes/GET "/static/*" (css-js-or-404 (route :*)))
(routes/GET "/" (serve-file static-dir "index.html"))
)
(jetty/defserver neenaj-server
{:port 80}
"/*" home)
(jetty/start neenaj-server)