Getting :remote-addr from the request object is typically the correct way to go unless you're sitting behind a load balancer. In that case your load balance may add a header e.g. x-forwarded-for to the request. Which would make something like this appropriate. (or (get-in request [:headers "x-forwarded-for"]) (:remote-addr request)) ...
unit-testing,session,clojure,ring
As per the suggestion by James Reeves through twitter, I was able to solve this problem by using peridot. It has session handling for writing tests.
tomcat,clojure,websocket,elastic-beanstalk,ring
Yes, http-kit is meant to be used in lieu of Tomcat, but you can use a reverse proxy like nginx. If that's something you really don't want to do, you could consider using Pedestal with SSE instead of websockets. Other than that, it doesn't look like there are any ring...
You need to invoke lein ring uberjar to generate a self-start server you can run with java -jar target/uberjar/yourproject-0.1.0-SNAPSHOT-standalone.jar I suggest you to use the standalone one to avoid dealing with dependencies Edited to include the specific command...
javascript,clojurescript,compojure,ring,cljsbuild
The compiler is optimized for generating one file per app. You could use multiple builds to do something like what you want, but you would have common code and blobs in both pages (builds), which is not optimal.
ring.middleware.params/parse-params expects only to receive a query parameter string so you need to remove everything before and including the ?, something like this will work: (#'ring.middleware.params/parse-params (second (.split "http://www.youtube.com/watch?v=P76Vbsk_3J0" "\\?")) "UTF-8") ;=> {"v" "P76Vbsk_3J0"} Note that you are using a function that is not a part of the public API....
To print to a string, use pr-str. Or use println to print to the REPL. (pr-str {:a 1}) ;=> "{:a 1}" (println {:a 1}) ;=> nil ***REPL contains output*** If you want more options and pretty printing, you could try clojure.pprint or fipp (require '[clojure.pprint :refer [pprint]]) (pprint {:a 1});...
Long live lib-noir and its wrap-force-ssl fn. I just needed to change it a bit to fit my needs (I have a SSL cert. for one subdomain even if my clojure app handles more then one domain) Here's my fn: (defn wrap-force-ssl "Almost like in lib-noir. If the request's scheme...
That's looking wrong. :ring {:handler (webdev.core/-main) :port 8000} (webdev.core/-main) means running your main function and delegating the result of the main Function as the handler to the ring-plugin. Try using something more like this when using lein ring ... :ring {:handler webdev.core/app :port 8000} ...
emacs,clojure,leiningen,ring,cider
Use latest lein-ring plugin version 0.9.2 and add :nrepl-middleware containing vector of nrepl-middlewares to :repl-options in your project.clj For example, I create the project by lein new compojure-app my-app. Then, I tested it by creating a empty leiningen profile in ~/.lein/profiles.clj ex. {:yolo {}} and starting ring server by lein...
The built in function clojure.set/rename-keys will do this nicely, though like all things in clojure there are several approaches. So lets walk through the process. What you have is very close to working. If I just lookup each by it's original string key, we can see it work: user> (def...
clojure,read-eval-print-loop,ring,compojure
#'app-routes is a reader macro that expands to (var app-routes). When a var is used as if it were a function, it is dereferenced anew on each invocation, and then the value returned by that deref is called. If you were to supply app-routes as the argument, the compiler would...
Here is comporoute, a ring handler without any macro magic, aimed at composability and extensibility. Even though it's in early alpha state it has precise docstrings already. It has a feature called inner middleware to solve the issue you are having. You may (and should) use it only for what...
Your use-case is exactly what Leiningen profiles are for. For example lein with-profile test ring server ...
The Lein-Ring plugin uses an embedded Jetty web server, while Aleph uses the asynchronous Netty web server. The aleph.http/wrap-aleph-handler middleware is designed only to work with a Netty server started with aleph.http/start-http-server function.
Ok, so the way to do it is with a regular expression and a context: (defroutes routes (context ["/:base-route" :base-route (re-pattern base-route)] [base-route] (GET "/user" [] (str "base: " base-route " user")) (GET "/settings" [] (str "base: " base-route " settings")))) ...
The ring middleware wrap-reload will do this for you. There is also a very nice leiningen template called Chestnut which will set up a project for you with Figwheel and an auto reloading Ring backend. This question shows an example of wrap-reload usage Compojure development without web server restarts...
clojure,ring,compojure,csrf-protection
The problem was that ring-defaults (which replaces the compojure.handler namespace in compojure >= 1.2) automatically uses ring anti-forgery in the usual mode of use: (defroutes app-routes (GET "/" [] (generate-string {:csrf-token *anti-forgery-token*})) (POST "/send" [email] "ok") (resources "/") (not-found "Not Found")) (def app (-> app-routes (wrap-defaults site-defaults))) So two anti-forgery...
clojure,oauth-2.0,ring,compojure,luminus
Based on the documentation for Google's OAuth2 for web servers here, the flow consists of the following steps: Your application redirects a browser to a Google URL; the URL includes query parameters that indicate the type of access being requested. The result is an authorization code, which Google returns to...
Found a solution. Turns out this problem is 'somewhat' related to Compojure/Ring: Why doesn't a session with cookie-store survive a server restart?, which explains that 2 session middleware are being used: One by compojure, one by wrap-session. After changing both middleware to the same storage engine, the atom is filled...
clojure,ring,compojure,http-kit
You can use compojure's routes function. You can also pass several handlers to defroutes, an example is provided below: (defroutes get-routes (GET "/events" [] "Event API") (GET "/" [] "Welcome")) (defroutes post-routes (POST "/events" [] "Post Event API")) (def all-routes (routes get-routes post-routes)) (defn -main [] (run-server all-routes {:port 5000}))...
intellij-idea,clojure,ring,compojure
You want to run the server from inside the repl? Add [ring/ring-jetty-adapter "1.3.1"] as a dependency In the REPL: (require 'ring.adapter.jetty) (require 'quals.core.handler) ; require YOUR ns containing the handler (ring.adapter.jetty/run-jetty quals.core.handler/app {:port 3004}) You can see all the parameters you can pass here: http://mmcgrana.github.io/ring/ring.adapter.jetty.html There you have it, the...
response is return a body. you code is (response requri),but the param of the funtion reponse is html body,not a uri,you can use the this function like this (ns foo (:require [ring.util.response :as response])) (def requi "/") (-> (response/redirect requri) (assoc :session new-session) (assoc :headers {"Content-Type" "text/html"})) ps: if you...
compojure's destructuring tries to access the query/form parameter :req in your example, not the whole request. You have two possibilities: (POST "..." req ...) and (POST "..." [something :as req] ...) Both store the request in req, the second variant allows you to still use destructuring , though....
I'm not very familiar with rook, and after taking a quick skim of the docs and a bit of the code I don't see static resources baked into it. If this is in error, please forgive me. It looks like rook does a lot, but in the end it's still...
clojure,swagger,ring,compojure
There is no definition in the Swagger Spec for the "missed everything else" default handler of Compojure. Swagger is about documenting existing apis, not the non-existing. Just discussed about this at #swagger on freenode. Still, you can describe the default routes manually with compojure-api, created a sample here: https://gist.github.com/ikitommi/cdf19eeaf4918efb051a. Note:...
The idiomatic way to do this is to use leiningen profiles, using the :dev profile. You can then ensure inside the dev profile that your ClojureScript build is happening without optimization, cf. the leiningen cljsbuild compilation profiles. If you want to be able to identify the devserver running, you can...
python,clojure,python-requests,ring,http-kit
I found how to fix this, but no satisfactory explanation. I was using wrap-json-response Ring middleware to take a HashMap and convert it to JSON. I switched to doing my own conversion in my handler with json/write-str, and this fixes it. At a guess it might be something to do...
because ring just uses function composition for middleware you can simply wrap friend around the call to wrap defaults: (def app (my-additional-mieddleware (wrap-defaults app-routes site-defaults) arguments to my additional middleware)) or you can thread it (for instance when you have several middlewares): (def app (-> (wrap-defaults app-routes site-defaults) (friend-stuff arg...
twitter-bootstrap,clojure,ring,compojure
Bower fulfils my requirements. Prerequisites are installing Bower through NPM and lein-bower Leiningen plugin. Below are the configuration details I had to add to project.clj: :plugins [[lein-bower "0.5.1"]] :bower-dependencies [[bootstrap "3.3.2"]] :bower {:directory "resources/public/lib"} @Aleš Roubíček - thanks for your comment....
It seems a bit of a risky proposition from a security and maintainability standpoint to let the Internet call any symbol in your namespace as a function, so my thought would be to instead do something like: Prepare a white-list of functions users should be able to request, in the...
clojure,type-conversion,ring,compojure
This is not currently possible with only Compojure. You could use Prismatic schema coercion. (require '[schema.core :as s]) (require '[schema.coerce :as c]) (require '[compojure.core :refer :all]) (require '[ring.middleware.params :as rparams]) (def data {:para1 s/Str :para2 s/Int s/Any s/Any}) (def data-coercer (c/coercer data c/string-coercion-matcher )) (def get-uri (GET "/uri" r (let...
facebook,clojure,leiningen,compojure,ring
I think the basic answer to your question is that functional programming is more about input and output (think of a mathematical function), whereas imperative programming tends to be more about side effects and mutable data. Instead of thinking, "what do I need to do?", think, "what kind of data...
clojure,nullpointerexception,ring
Use when-let or the similar if-let to check whether you actually have a session or not: (defn logged-in-verify [ring-handler] (fn new-ring-handler [request] ;;verify that the scrypt hash of email and timestamp matches. (if-let [session (:session request)] (let [email (:ph-auth-email session) token (:ph-auth-token session) timestamp (:ph-auth-timestamp session)] (if (scryptgen/check (str email...
EDIT: As an answer to the updated question, the wrap-edn-params function consumes the body of the request by fully reading the :body InputStream. Compojure routes passes the request to each parameter handler until a non nil value is returned. In this case, whichever handler is passed to routes as the...
Your procfile should be something like this: web: lein ring server-headless $PORT To check your application can run properly on heroku, you can use a foreman port, which makes use of the procfile. These days I am using gaffer, and the documentation on Procfile for Heroku is here....
unit-testing,clojure,ring,compojure,midje
I discovered today that I had my scopes confused - the let block introducing response was outside of the fact call that included the provided. Thus the response was created before the provided was invoked. Working code which passed this early test instead used the against-background call (facts "It returns...
Turns out the problem was the order of my middlewares. I needed to wrap-json-body after friend-authenticate.