Fork me on GitHub
#ring
<
2017-03-04
>
scknkkrer17:03:31

guys, I wanna use a wrapper for my routes. `(defn wrap-metamiddlewares [rs] (reduce (fn [xs r] (conj xs (reduce (fn [ir m] (apply compojure.core/wrap-routes ir m)) r (-> r meta :middleware)))) [] rs))` for defined routes like this; ` (defroutes ^{:doc “............" :middleware [[buddy.auth.accessrules/restrict {:handler #(identity true) :on-error (layout/error-page {:status 403 :message ""})}]]} main-route ............))`

scknkkrer17:03:26

My code work but I can’t go to page, it takes me to this; `(defn wrap-context [handler] (fn [request] (binding [app-context (if-let [context (:servlet-context request)] ;; If we're not inside a servlet environment ;; (for example when using mock requests), then ;; .getContextPath might not exist (try (.getContextPath ^ServletContext context) (catch IllegalArgumentException _ context)) ;; if the context is not specified in the request ;; we check if one has been specified in the environment ;; instead (:app-context env))] (handler request))))` Wrong number of args (1)

scknkkrer17:03:43

what is the relation of this with my wrappers ?

sova-soars-the-sora17:03:43

@weavejester do you think something like the following would work

sova-soars-the-sora17:03:59

`
(def main-ring-handler
  "**NB**: Sente requires the Ring `wrap-params` + `wrap-keyword-params`
  middleware to work. These are included with
  `ring.middleware.defaults/wrap-defaults` - but you'll need to ensure
  that they're included yourself if you're not using `wrap-defaults`."

  (let [ssd ring.middleware.defaults/secure-site-defaults]
        (assoc ssd :proxy true)

        (ring.middleware.defaults/wrap-defaults
                 ring-routes
                        ssd)))
`

sova-soars-the-sora17:03:58

because I can access my site using r.m.d/site-defaults but simply get a http://localhost redirect when I am trying to use the secure-site-defaults, even with the code above

sova-soars-the-sora18:03:48

@scknkkrer do you know which fxn is expecting more args?

scknkkrer18:03:36

Yeah, I am getting close to fix. But I don’t get it. buddy.auth.accessrules/restrict wrapper is expecting an argument a map for auth fn and error value.

scknkkrer18:03:14

I am trying with another middleware and getting normal page. 😄 I don’t get it guys...

sova-soars-the-sora18:03:08

@scknkkrer have not used buddy to comment intelligently.. it's for authentication right?

scknkkrer18:03:47

I solved it, but I am really confused much more than 5 min ago.

scknkkrer18:03:20

I just used fn function not the syntax sugar.

weavejester19:03:29

@sova You’re not assigning :proxy to true. Remember that maps in Clojure are immutable.

sova-soars-the-sora19:03:18

But something like

sova-soars-the-sora19:03:52

(let [ssd (assoc ring.middleware.defaults/secure-site-defaults :proxy true)] ... and then using ssd would work, yes?

sova-soars-the-sora19:03:46

Man I wish someone would whack me over the head with a functional programming baton, but i don't think it'd materialize until the instant I needed it

weavejester19:03:24

Assuming that your proxy is set up correctly and there aren’t any other issues.