compojure

How To Integrate Clojure Web Applications in Apache

↘锁芯ラ 提交于 2019-12-03 00:45:51
问题 Note Given this OP was written about two years ago, rather than ask the same question again, I am wondering if step-by-step instructions exist, so that I can integrate a Noir or other Clojure web application into Apache, whether it's Jetty, Tomcat, or something else. Similar instructions exist for Django, and I think I understand that Python is being run in Django's case as an engine rather than a ring framework, so things are more complicated with Clojure web applications. End Note I'm

how does one _model_ data from relational databases in clojure?

时光怂恿深爱的人放手 提交于 2019-12-03 00:09:49
I have asked this question on twitter as well the #clojure IRC channel, yet got no responses. There have been several articles about Clojure-for-Ruby-programmers, Clojure-for-lisp-programmers.. but what is the missing part is Clojure for ActiveRecord programmers . There have been articles about interacting with MongoDB, Redis, etc. - but these are key value stores at the end of the day. However, coming from a Rails background, we are used to thinking about databases in terms of inheritance - has_many, polymorphic, belongs_to, etc. The few articles about Clojure/Compojure + MySQL ( ffclassic )

Compojure routes with different middleware

旧时模样 提交于 2019-12-02 17:16:49
I'm currently writing an API in Clojure using Compojure (and Ring and associated middleware). I'm trying to apply different authentication code depending on the route. Consider the following code: (defroutes public-routes (GET "/public-endpoint" [] ("PUBLIC ENDPOINT"))) (defroutes user-routes (GET "/user-endpoint1" [] ("USER ENDPOINT 1")) (GET "/user-endpoint2" [] ("USER ENDPOINT 1"))) (defroutes admin-routes (GET "/admin-endpoint" [] ("ADMIN ENDPOINT"))) (def app (handler/api (routes public-routes (-> user-routes (wrap-basic-authentication user-auth?))))) (-> admin-routes (wrap-basic

How To Integrate Clojure Web Applications in Apache

可紊 提交于 2019-12-02 14:13:50
Note Given this OP was written about two years ago, rather than ask the same question again, I am wondering if step-by-step instructions exist, so that I can integrate a Noir or other Clojure web application into Apache, whether it's Jetty, Tomcat, or something else. Similar instructions exist for Django, and I think I understand that Python is being run in Django's case as an engine rather than a ring framework, so things are more complicated with Clojure web applications. End Note I'm deeply in love with Clojure, and Compojure seems like a neat web framework. But it all fell apart when I

How do you enable https and http->https redirects in ring / compojure

五迷三道 提交于 2019-12-01 03:17:43
问题 I am developing a RESTful app, for which I need to redirect requests coming in from an http address to it's https equivalent. I cannot seem to be able to enable https using ring/compojure. Anyone have some useful tutorials and/or links? I haven't found any. The documentation doesn't have anything useful either. 回答1: Its very simple. If you want to enable HTTPS support in your web app, just do the following: Generate a Java KeyStore(.jks) file using a linux tool called keytool. In the ring map

How to run an arbitrary startup function in a ring project?

淺唱寂寞╮ 提交于 2019-11-30 17:41:59
I've got a compojure/ring application I currently run with lein ring server that I'd like to compile to a .war so I can deploy it. I've got a definition, however, just like (def foo (start-scheduler)) That blocks the compilation and the generation of the .war. To circumvent this, I thought about moving the call to a startup function, but how would I call it when the server launches? If I put the call inside the handler, I'd end up with the same problem as before. Thanks! In your project.clj when declaring your Ring handler you can also specify an init (and destroy) function that is run when

Passing state as parameter to a ring handler?

回眸只為那壹抹淺笑 提交于 2019-11-30 11:54:26
How does one inject state into ring handlers most conveniently (without using global vars)? Here is an example: (defroutes main-routes (GET "/api/fu" [] (rest-of-the-app the-state))) (def app (-> (handler/api main-routes))) I would like to get the-state into the compojure handler for main-routes . The state might be something like a map created with: (defn create-app-state [] {:db (connect-to-db) :log (create-log)}) In a non ring application I would create the state in a main function and start injecting it, or parts of it, as function parameters to the different components of the application.

Missing form parameters in Compojure POST request

允我心安 提交于 2019-11-30 11:18:01
I'm having problems getting the form parameters in the following Compojure example: (ns hello-world (:use compojure.core, ring.adapter.jetty) (:require [compojure.route :as route])) (defn view-form [] (str "<html><head></head><body>" "<form method=\"post\">" "Title <input type=\"text\" name=\"title\"/>" "<input type=\"submit\"/>" "</form></body></html>")) (defroutes main-routes (GET "/" [] "Hello World") (GET "/new" [] (view-form)) (POST "/new" {params :params} (prn "params:" params)) (route/not-found "Not Found")) (run-jetty main-routes {:port 8088}) When submitting the form the output is

Using a javax.servlet.Filter with Compojure

跟風遠走 提交于 2019-11-30 05:25:56
I'm trying to build a simple web site using Clojure / Compojure and want to feed apply a servlet filter to the request / response (i.e. a standard javax.servlet.Filter instance). e.g. if the current source code is: (defroutes my-app (GET "/*" (html [:h1 "Hello Foo!!"])) ) I would like to add a filter like this: (defroutes my-app (GET "/*" (FILTER my-filter-name (html [:h1 "Hello Foo!!"]))) ) Where my-filter-name is some arbitrary instance of javax.servlet.Filter. Any idea how to do this effectively and elegantly? mikera Ok I've now got this working! Thanks cgrand for the pointers in the right

Serve index.html at / by default in Compojure

做~自己de王妃 提交于 2019-11-30 02:54:42
I have a static file called index.html that I'd like to serve when someone requests / . Usually web servers do this by default , but Compojure doesn't. How can I make Compojure serve index.html when someone requests / ? Here's the code I'm using for the static directory: ; match anything in the static dir at resources/public (route/resources "/") amalloy This would be a pretty simple Ring middleware: (defn wrap-dir-index [handler] (fn [req] (handler (update-in req [:uri] #(if (= "/" %) "/index.html" %))))) Just wrap your routes with this function, and requests for / get transformed into