This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-28
Channels
- # aws (7)
- # beginners (69)
- # boot (67)
- # cider (9)
- # cljs-dev (159)
- # cljsrn (2)
- # clojars (25)
- # clojure (345)
- # clojure-austin (9)
- # clojure-berlin (1)
- # clojure-dusseldorf (10)
- # clojure-italy (3)
- # clojure-nl (1)
- # clojure-portugal (1)
- # clojure-spec (73)
- # clojure-uk (59)
- # clojurescript (163)
- # clojurewerkz (1)
- # component (26)
- # core-matrix (2)
- # cursive (20)
- # datascript (32)
- # datomic (15)
- # dirac (16)
- # emacs (3)
- # hoplon (35)
- # jobs-discuss (87)
- # jobs-rus (95)
- # luminus (15)
- # om (135)
- # om-next (3)
- # onyx (47)
- # pedestal (67)
- # perun (74)
- # play-clj (4)
- # portland-or (1)
- # proton (4)
- # re-frame (13)
- # reagent (18)
- # remote-jobs (17)
- # rum (20)
- # specter (11)
- # untangled (101)
- # yada (18)
hi, wonder if there is some examples of simulating multi-part form submission in testing pedestal application? eg. for testing file uploading. using pedestal's response-for macro.
Hi, is it possible to use function to build routes? I am trying this:
::http/routes (build-routes)
(defn build-routes
(route/expand-routes #{[…]}))
But facing this:
You're trying to use something as an interceptor
that isn't supported by the protocol; Perhaps you need to extend it? {:t nil, :type nil}
Is it good approach to build routes this way?
(def route-table
#{["/" :get ['pages/root]]
["/sign-up" :get ['pages/show-sign-up]]
["/sign-up" :post ['pages/sign-up]]
["/sign-in" :get ['pages/show-sign-in]]
["/sign-in" :post ['pages/sign-in]]})
(def common-interceptors
[http/html-body
(using-component :db)
(session {:store (cookie/cookie-store {:key "some-key12345678"})})])
(defn build-interceptors [verb interceptors]
(let [interceptors (apply conj common-interceptors interceptors)]
(if (= verb :get)
interceptors
(into [(body-params) keyword-params] interceptors))))
(defn browser-stack [[path verb interceptors]]
[path verb (build-interceptors verb interceptors)])
(def routes
(route/expand-routes (into #{} (map browser-stack route-table))))
@kirill.salykin there's nothing wrong with building your routes programmatically, although given your example, I'd build the route-table explicitly. IMO it would be easier to reason about
@kirill.salykin re: the error you're seeing, it may be due to how you refer to your handlers in the route table. Try using back-ticks instead of single quotes
@ddeaguiar thanks for response Thought it makes no sens to repeat (body-params) etc
I see this error only when I am trying to implemet routes as function defn routes []
thanks!
@kirill.salykin also, you don't need to call route/expand-routes
pedestal will do it for me because set used?
so I suspect what's happening is that the verbose route map produced by expand routes is trying to be expanded again by Pedestal's internals
https://github.com/pedestal/pedestal/blob/master/route/src/io/pedestal/http/route.clj#L355
@kirill.salykin The message you're getting includes the value and type that Pedestal is trying to convert to an interceptor. The value is nil, so I suspect that your interceptor vector after browser-stack may have some issues. Can you print the value of the set after (into #{} (map browser-stack route-table))
?
@mtnygard everything works I am facing issue if I am trying to use this:
(def routes
(route/expand-routes (into #{} (map browser-stack route-table))))
as function, eg :
(defn routes []
(route/expand-routes (into #{} (map browser-stack route-table))))
(defn build-routes []
(fn []
(doseq [ns-sym (modified-namespaces)]
(require ns-sym :reload))
routes))
(def pedestal-config
{::http/host "0.0.0.0"
::http/port 8080
::http/type :jetty
::http/join? true
::http/resource-path "/public"
::http/routes (build-routes)})
routes defined above
OK, so you're using build-routes to do auto refresh. When you use (defn routes ...), did you change the last expression in build-routes to be a call to the routes function?
yes I used this version
(defn build-routes []
(fn []
(doseq [ns-sym (modified-namespaces)]
(require ns-sym :reload))
(routes)))
of course
give me couple minutes
#object[blog$build_routes$fn__16210 0x4aa430d9 "[email protected]"]
sorry 😞
clojure.lang.ExceptionInfo: You're trying to use something as an interceptor that isn't supported by the protocol; Perhaps you need to extend it?
So then the problem is definitely with the data structure being passed to expand-routes. Can you show me the output of (into #{} (map browser-stack route-table))
all route related declared in blog.web.routes when I calling (route) being in blog.web.routes this is returned:
({:path "/sign-in", :method :get, :path-re #"/\Qsign-in\E", :path-parts ["sign-in"], :interceptors [#Interceptor{:name :io.pedestal.http/html-body} #Interceptor{:name :io.pedestal.http.ring-middlewares/session} #Interceptor{:name :blog.system.pedestal/using-component} #Interceptor{:name :io.pedestal.http.params/keyword-params} #Interceptor{:name }], :route-name :blog.web.pages/show-sign-in, :path-params []} {:path "/sign-in", :method :post, :path-re #"/\Qsign-in\E", :path-parts ["sign-in"], :interceptors [#Interceptor{:name :io.pedestal.http.body-params/body-params} #Interceptor{:name :io.pedestal.http/html-body} #Interceptor{:name :io.pedestal.http.ring-middlewares/session} #Interceptor{:name :blog.system.pedestal/using-component} #Interceptor{:name :io.pedestal.http.params/keyword-params} #Interceptor{:name }], :route-name :blog.web.pages/sign-in, :path-params []} {:path "/sign-up", :method :post, :path-re #"/\Qsign-up\E", :path-parts ["sign-up"], :interceptors [#Interceptor{:name :io.pedestal.http.body-params/body-params} #Interceptor{:name :io.pedestal.http/html-body} #Interceptor{:name :io.pedestal.http.ring-middlewares/session} #Interceptor{:name :blog.system.pedestal/using-component} #Interceptor{:name :io.pedestal.http.params/keyword-params} #Interceptor{:name }], :route-name :blog.web.pages/sign-up, :path-params []} {:path "/sign-up", :method :get, :path-re #"/\Qsign-up\E", :path-parts ["sign-up"], :interceptors [#Interceptor{:name :io.pedestal.http/html-body} #Interceptor{:name :io.pedestal.http.ring-middlewares/session} #Interceptor{:name :blog.system.pedestal/using-component} #Interceptor{:name :io.pedestal.http.params/keyword-params} #Interceptor{:name }], :route-name :blog.web.pages/show-sign-up, :path-params []} {:path "/", :method :get, :path-re #"/\Q\E", :path-parts [""], :interceptors [#Interceptor{:name :io.pedestal.http/html-body} #Interceptor{:name :io.pedestal.http.ring-middlewares/session} #Interceptor{:name :blog.system.pedestal/using-component} #Interceptor{:name :io.pedestal.http.params/keyword-params} #Interceptor{:name }], :route-name :blog.web.pages/root, :path-params []})
but, when invoking ((build-routes) being in blog
namespace having this declaration [blog.web.routes :refer [routes]
everything breaks
can it be some name overlap?
I’ll push it to github a bit later
syntax quoted
let me recheck, i have a feeling that i’ve used just ‘ symbol
everything works
thanks
I am so sorry for this stupid error 😞
thanks a lot!
Kudos to @ddeaguiar. He spotted that a while ago.
but last-interceptor still has empty name
((build-routes))
({:path "/sign-up", :method :get, :path-re #"/\Qsign-up\E", :path-parts ["sign-up"], :interceptors [#Interceptor{:name :io.pedestal.http/html-body} #Interceptor{:name :io.pedestal.http.ring-middlewares/session} #Interceptor{:name :blog.system.pedestal/using-component} #Interceptor{:name :io.pedestal.http.params/keyword-params} #Interceptor{:name }], :route-name :blog.web.pages/show-sign-up, :path-params []} {:path "/sign-up", :method :post, :path-re #"/\Qsign-up\E", :path-parts ["sign-up"], :interceptors [#Interceptor{:name :io.pedestal.http.body-params/body-params} #Interceptor{:name :io.pedestal.http/html-body} #Interceptor{:name :io.pedestal.http.ring-middlewares/session} #Interceptor{:name :blog.system.pedestal/using-component} #Interceptor{:name :io.pedestal.http.params/keyword-params} #Interceptor{:name }], :route-name :blog.web.pages/sign-up, :path-params []} {:path "/sign-in", :method :post, :path-re #"/\Qsign-in\E", :path-parts ["sign-in"], :interceptors [#Interceptor{:name :io.pedestal.http.body-params/body-params} #Interceptor{:name :io.pedestal.http/html-body} #Interceptor{:name :io.pedestal.http.ring-middlewares/session} #Interceptor{:name :blog.system.pedestal/using-component} #Interceptor{:name :io.pedestal.http.params/keyword-params} #Interceptor{:name }], :route-name :blog.web.pages/sign-in, :path-params []} {:path "/sign-in", :method :get, :path-re #"/\Qsign-in\E", :path-parts ["sign-in"], :interceptors [#Interceptor{:name :io.pedestal.http/html-body} #Interceptor{:name :io.pedestal.http.ring-middlewares/session} #Interceptor{:name :blog.system.pedestal/using-component} #Interceptor{:name :io.pedestal.http.params/keyword-params} #Interceptor{:name }], :route-name :blog.web.pages/show-sign-in, :path-params []} {:path "/", :method :get, :path-re #"/\Q\E", :path-parts [""], :interceptors [#Interceptor{:name :io.pedestal.http/html-body} #Interceptor{:name :io.pedestal.http.ring-middlewares/session} #Interceptor{:name :blog.system.pedestal/using-component} #Interceptor{:name :io.pedestal.http.params/keyword-params} #Interceptor{:name }], :route-name :blog.web.pages/root, :path-params []})
Ah, I see what's happening. `pages/root gets turned into the fully-qualified symbol. If you had that directly in your route table it would still be a symbol when Pedestal turned it into an interceptor.
I'm glad it's working. I'd be happy to take a closer look at the interceptor name thing later on when you've posted the code.
sure, thanks a lot @ddeaguiar and @mtnygard