Skip to content
This repository has been archived by the owner on Jan 23, 2018. It is now read-only.

Commit

Permalink
Include starter static pages for 404 and 500.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Aug 8, 2012
1 parent 84929dc commit 2888ad4
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lein-template/src/leiningen/new/heroku.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
["Procfile" (render "Procfile" data)]
["README.md" (render "README.md" data)]
["src/{{dir}}/web.clj" (render "web.clj" data)]
["resources/500.html" (render "500.html" data)]
["resources/404.html" (render "404.html" data)]
["test/{{dir}}/web_test.clj" (render "test.clj" data)]
["project.clj" (render "project.clj" data)]))
(println "Generated new Heroku project in" name "directory."))
21 changes: 21 additions & 0 deletions lein-template/src/leiningen/new/heroku/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Page Not Found</title>
<style type="text/css">
body {
font-family: "Ubuntu Light", helvetica, sans-serif;
width: 960px;
margin: 3em auto;
}
</style>
</head>
<body>
<!-- TODO: replace this with something that matches your app style -->
<h1>Page Not Found</h1>
<p>There's no page at the address you requested. If you entered it
by hand, check for typos. If you followed a link or a bookmark,
it may need to be updated.</p>
</body>
</html>
20 changes: 20 additions & 0 deletions lein-template/src/leiningen/new/heroku/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Error</title>
<style type="text/css">
body {
font-family: "Ubuntu Light", helvetica, sans-serif;
width: 960px;
margin: 3em auto;
}
</style>
</head>
<body>
<!-- TODO: replace this with something that matches your app style -->
<h1>Error</h1>
<p>Something went wrong. Try again, and if the problem persists
please contact support.</p>
</body>
</html>
2 changes: 1 addition & 1 deletion lein-template/src/leiningen/new/heroku/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
:min-lein-version "2.0.0"
:plugins [[environ/environ.lein "0.2.1"]]
:hooks [environ.leiningen.hooks]
:profiles {:dev {:env {:dev true}}})
:profiles {:production {:env {:production true}}})
20 changes: 16 additions & 4 deletions lein-template/src/leiningen/new/heroku/web.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(ns {{name}}.web
(:require [compojure.core :refer [defroutes GET PUT POST DELETE ANY]]
[compojure.handler :refer [site]]
[compojure.route :as route]
[clojure.java.io :as io]
[ring.middleware.stacktrace :as trace]
[ring.middleware.session :as session]
[ring.middleware.session.cookie :as cookie]
Expand All @@ -24,16 +26,26 @@
(GET "/" []
{:status 200
:headers {"Content-Type" "text/plain"}
:body (pr-str ["Hello" :from 'Heroku])}))
:body (pr-str ["Hello" :from 'Heroku])})
(ANY "*" []
(route/not-found (slurp (io/resource "404.html")))))

(defn wrap-error-page [handler]
(fn [req]
(try (handler req)
(catch Exception e
{:status 500
:headers {"Content-Type" "text/html"}
:body (slurp (io/resource "500.html"))}))))

(defn -main [& [port]]
(let [port (Integer. (or port (env :port) 5000))
;; TODO: heroku config:add SESSION_SECRET=$RANDOM_16_CHARS
store (cookie/cookie-store {:key (env :session-secret)})]
(jetty/run-jetty (-> #'app
((if (env :dev)
trace/wrap-stacktrace
identity))
((if (env :production)
wrap-error-page
trace/wrap-stacktrace))
(site {:session {:store store}}))
{:port port :join? false})))

Expand Down

0 comments on commit 2888ad4

Please sign in to comment.