This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-11
Channels
- # aleph (1)
- # architecture (18)
- # beginners (57)
- # boot (13)
- # cider (47)
- # cljs-dev (28)
- # cljsjs (13)
- # cljsrn (39)
- # clojure (258)
- # clojure-greece (16)
- # clojure-italy (2)
- # clojure-miami (1)
- # clojure-nl (9)
- # clojure-poland (15)
- # clojure-russia (369)
- # clojure-spec (53)
- # clojure-uk (49)
- # clojureremote (3)
- # clojurescript (135)
- # core-matrix (1)
- # cursive (11)
- # datascript (3)
- # datomic (4)
- # emacs (12)
- # figwheel (13)
- # hoplon (7)
- # interop (7)
- # jobs-discuss (33)
- # lumo (28)
- # off-topic (15)
- # om (7)
- # onyx (26)
- # pedestal (10)
- # perun (1)
- # planck (10)
- # re-frame (54)
- # reagent (16)
- # ring (5)
- # ring-swagger (50)
- # rum (2)
- # spacemacs (2)
- # unrepl (125)
- # untangled (12)
Hey guys, I am experience an incredibly frustrating issue. We are attempting to add compojure-api to our application to manage our api endpoint. For our api-endpoint everything is doing GREAT! However, for other endpoints on our app we’re still using plain compojure. One of those endpoints expects transit+json in the body and it is getting nothing. I have since mocked the InputStream in the body to one that will log every read from it and I found out that the body is being read in the ring.middleware.format-params middleware which is being applied by the compojure-api.
So my question is, is there a way to have the compojure-api middleware be applied ONLY to the compojure-api routes?
@kasuko No. It is impossible for the middleware to know if route will be matched so it has to read the body always.
It is possible to work around this if all your Compojure-apis are under some prefix like /api, then you can mount Compojure-api handler under context
but if your top-level handler is something like (or (compojure-api req) (normal-compojure req))
the Compojure-api middleware will run always
I'd recommend just porting all the endpoints to Compojure-api, changing the requires from compojure to compojure.api should be enough
As for converting them all the compojure-api, we don’t really want to schema our other endpoints right now
compojure-api doesn't require schema
everything that works in compojure, should work the same in compojure-api
@juhoteperi Nope, I switched the route to be a compojure-api route and the middleware is still destroying the body of the request
@kasuko I don't quite understand what you are doing
Is defapi
or api
your top level handler or not?
Is it directly under context
?
:api-endpoint (system.endpoint/new-endpoint (fn [_] handler/app-api))
:app-endpoint (component/using (system.endpoint/new-endpoint (fn [_] handler/app-routes))
[:api-endpoint])
where handler/app-api
is pretty much just
(def app-api
(api/api {...}
(api/context "/api" []
(api/middleware
[[auth/wrap-authorize #{"user"}]]
(api/context "/search" []
:tags ["search"]
search.handler/routes)
(api/context "/reports" []
:tags ["reports"]
reports.handler/routes)
(api/context "/dashboard" []
:tags ["dashboard"]
dashboard.handler/routes)))))
@kasuko you should not have both api/api and api/middleware
ah now wait
right its compjure.api.core/middleware
this is not going to work
what does merge those two endpoints?
oh right, app-endpoint uses api-endpoint
you app-endpoint should have context "/api"
and api-endpoint shouldn't have that
your app-routes probably does something like (routes api-routes (GET "/index.html" ...) what-ever)
which means that all the middleware in api-routes is always run
doesn't app-routes use api-endpoint? why does that component use :api-endpoint?
Whoops, sorry ya I was simplifying and forgot I was. The actual issue is with a 3rd endpoint for client performance statistics gathering :S
It’s routes are
(defroutes client-perf-routes
(POST "/client-perf-stats" request
(let [body (transit-utils/parse-body request)]
(client-perf-stats body))
(rh/no-content))
(POST "/client-perf-slow-frame" request
(rh/no-content)))
In the /client-perf-stats route the :body of the request
is empty as it’s already been read
yes, it doesn't matter at all which one your are using
ring middlewares are ran before route matching happens
I'd recommend just using api
at the top-most handler, which I guess is the app-routes
. I don't see benefit of only using it for api endpoints
But if you need to separate, you can do it this way: https://gist.github.com/Deraen/6ab53a0a3e1c56dde0df3a5d6470f72c
That will just do (routes api-endpoint app-endpoint)
Which is same as (fn [req] (or (api-endpoint req) (app-endpoint req)))
alright, I will remove the api-endpoint and most likely just add it to the app-routes as per your advice
I have a compojure-api app which contains an endpoint accepting file uploads. Basic functionality works as desired however, I'm running into a 413 Request Entity Too Large
for files over 8MB. How can the max allowed size be specified?