From 268267c9e45351322ec61800f5b9900d83f40a24 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 29 Nov 2009 00:27:23 +0100 Subject: Beginning of a rewrite in Clojure for use on the Google App Engine. --- src/run.clj | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/run.clj (limited to 'src/run.clj') diff --git a/src/run.clj b/src/run.clj new file mode 100644 index 0000000..2bc6c8e --- /dev/null +++ b/src/run.clj @@ -0,0 +1,49 @@ +;;; From: http://www.hackers-with-attitude.com/2009/08/intertactive-programming-with-clojure.html +;;; Copyright Robin Brandt, freiheit.com. + +(ns logikorr-jetty + (:use logikorr) + (:use compojure.server.jetty compojure.http compojure.control)) + +(defmacro with-app-engine + "testing macro to create an environment for a thread" + ([body] + `(with-app-engine env-proxy ~body)) + ([proxy body] + `(last (doall [(com.google.apphosting.api.ApiProxy/setEnvironmentForCurrentThread ~proxy) + ~body])))) + +(defn login-aware-proxy + "returns a proxy for the google apps environment that works locally" + [request] + (let [email (:email (:session request))] + (proxy [com.google.apphosting.api.ApiProxy$Environment] [] + (isLoggedIn [] (boolean email)) + (getAuthDomain [] "") + (getRequestNamespace [] "") + (getDefaultNamespace [] "") + (getAttributes [] (java.util.HashMap.)) + (getEmail [] (or email "")) + (isAdmin [] true) + (getAppId [] "local")))) + +(defn environment-decorator + "decorates the given application with a local version of the app engine environment" + [application] + (fn [request] + (with-app-engine (login-aware-proxy request) + (application request)))) + +(defn init-app-engine + "Initialize the app engine services." + ([] + (init-app-engine "/tmp")) + ([dir] + (com.google.apphosting.api.ApiProxy/setDelegate + (proxy [com.google.appengine.tools.development.ApiProxyLocalImpl] [(java.io.File. dir)])))) + +;; make sure every thread has the environment set up + +(defn start-logikorr [] + (init-app-engine) + (run-server {:port 8080} "/*" (servlet (environment-decorator logikorr)))) -- cgit v1.2.3