Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conflicted with ring.middleware.format.wrap-restful-format #123

Closed
pkvov opened this issue May 4, 2015 · 5 comments
Closed

conflicted with ring.middleware.format.wrap-restful-format #123

pkvov opened this issue May 4, 2015 · 5 comments

Comments

@pkvov
Copy link

pkvov commented May 4, 2015

i found it conflicted with ring.middleware.format.wrap-restful-format.
thanks && appreciate your wonderful library
here is my ring handler

32  (-> handler
33      (wrap-authorization auth/auth-backend)
34      (wrap-authentication auth/auth-backend)
35      (wrap-idle-session-timeout
36       {:timeout (* 60 30)
37        :timeout-response (redirect "/")})
38      (wrap-restful-format :formats [:json-kw :edn :transit-json :transit-msgpack])
39      (wrap-defaults (-> site-defaults
40                         (assoc-in [:session :store] (memory-store session/mem))
41                         (assoc-in [:security :anti-forgery] true)))
42      ;;(wrap-internal-error :log #(timbre/error %))
43      ))
@ptaoussanis
Copy link
Member

Hi @pkvov, you'll need to adjust your routing so that you're not applying unnecessary/incompatible middleware to Sente's routes (usu. one "/chsk" GET and one POST).

Does that help / make sense?

@pkvov
Copy link
Author

pkvov commented May 4, 2015

thanks @ptaoussanis .
i start from the Sente's example with the routes /chsk GET and POST. then i added middleware one by one, and found wrap-restful-format conflicted with Sendte, and i need this middleware to help me parse the parameters send from client, and this is very common to use Sendte with a ring stack web application.

@ptaoussanis
Copy link
Member

The "/chsk" routes are basically an implementation detail as used by Sente. You shouldn't be applying application-level middleware to them, does that make sense?

i need this middleware to help me parse the parameters send from client, and this is very common to use Sendte with a ring stack web application.

Sure, you can continue to use any middleware you want (incl. ring.middleware.format.wrap-restful-format) - just make sure to apply the middleware only to your own application-level routes - Sente's implementation routes must be excluded.

The "/chsk" routes need ring.middleware.defaults/wrap-defaults plus any CSRF middleware you like, but nothing else (no application-level middleware).

Your own routes can have any middleware you like. Does that make sense?

You can exclude application-level middleware from Sente in several ways, the quickest/easiest might be something like compojure.core/wrap-routes.

@pkvov
Copy link
Author

pkvov commented May 6, 2015

thanks alot @ptaoussanis , i finally understand.

do not mix Sente routes and middleware with application routes and middleware.
this post make it more clear
http://stackoverflow.com/questions/28016968/serving-app-and-api-routes-with-different-middleware-using-ring-and-compojure

@pkvov pkvov closed this as completed May 6, 2015
@ptaoussanis
Copy link
Member

No problem, happy you found a solution. Thanks for sharing the link, that'll be helpful for other folks that might run into this issue.

Cheers :-)

danielsz added a commit to danielsz/system that referenced this issue Dec 5, 2016
- Endpoints can specify middleware
- Routes will be recombined according to their middleware
- The Handler component can also specify middleware that will be applied to all endpoints/routes

This allows to address the use case when different routes need
different middleware. For example, Sente is incompatible with
`wrap-restful-format'.

taoensso/sente#123

Decomplecting routes and middleware also enables better
composition. Side-effectful middleware, such as wrap-params, consumes
the request body upon reading it. This means it should only be applied
once. Hence, web-centric libraries should never force such middleware
on the user, but rather let him apply any middleware needed on
recombined routes in the end application.

ring-clojure/ring-defaults#10

With our new implementation, it is possible to write libraries, for
example a social sign-in library, keep it totally separate from
application code, and then, with the Duct abstractions in `system',
compose endpoints with any middleware the application should need.
VenusPR added a commit to VenusPR/System_development that referenced this issue Mar 12, 2023
- Endpoints can specify middleware
- Routes will be recombined according to their middleware
- The Handler component can also specify middleware that will be applied to all endpoints/routes

This allows to address the use case when different routes need
different middleware. For example, Sente is incompatible with
`wrap-restful-format'.

taoensso/sente#123

Decomplecting routes and middleware also enables better
composition. Side-effectful middleware, such as wrap-params, consumes
the request body upon reading it. This means it should only be applied
once. Hence, web-centric libraries should never force such middleware
on the user, but rather let him apply any middleware needed on
recombined routes in the end application.

ring-clojure/ring-defaults#10

With our new implementation, it is possible to write libraries, for
example a social sign-in library, keep it totally separate from
application code, and then, with the Duct abstractions in `system',
compose endpoints with any middleware the application should need.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants