This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-28
Channels
- # announcements (3)
- # babashka (36)
- # beginners (77)
- # boot (3)
- # chlorine-clover (10)
- # cider (27)
- # clj-kondo (1)
- # cljs-dev (4)
- # clojure (256)
- # clojure-belgium (1)
- # clojure-europe (9)
- # clojure-uk (18)
- # clojuredesign-podcast (9)
- # clojurescript (54)
- # cryogen (8)
- # cursive (3)
- # data-science (1)
- # datomic (2)
- # duct (31)
- # events (1)
- # exercism (3)
- # fulcro (116)
- # joker (20)
- # kaocha (5)
- # meander (2)
- # nrepl (4)
- # off-topic (10)
- # other-languages (15)
- # re-frame (18)
- # reagent (4)
- # shadow-cljs (44)
- # sql (14)
- # tools-deps (17)
Hi All
Does anyone have an example of a Duct project that allows both secure and insecure routes. I know you have have a route specific middleware which I think would do this but is there a way to group routes together for specific middleware (rather than a route by route basis)?
many thanks
If you have the routes
v1/secure
And
v1/insecure
You could place the specific Middleware on secure and insecure routes. The shared Middleware could go on v1. Not sure if that's what you mean though
Hi @kevin.van.rooijen - would I then be able to define v1/secure/foo v1/secure/boo ? not quite sure how that works in config.edn.
I'm new to ataraxy so I'm assuming you can define a route with various middleware and have subroutes "inherit" that middleware?
Something like this I think
Something like this I think,
:duct.router/ataraxy
{:middleware {:middleware/global #ig/ref :my-app.middleware/global
:middleware/secure #ig/ref :my-app.middleware/secure
:middleware/insecure #ig/ref :my-app.middleware/insecure}
:routes
{"/v1"
^:middleware/global
{"/secure"
^:middleware/secure
{"/foo" [:my-app.handler/secure-foo]}
"/insecure"
^:middleware/insecure
{"/boo" [:my-app.handler/insecure-boo]}}}}
anything under /secure
will use :middleware/secure
.
anything under /insecure
will use :middleware/insecure
.
@kevin.van.rooijen - perfect - many thanks for this. Appreciate the help.
Hi @kevin.van.rooijen - a follow up question if I may. Where or how would I define multiple middleware to call. In the example above I'd like :middleware/global to call middleware-1 and middleware-2. Is that possible in EDN or would I have to define that in my-app-middleware-global ig/init to return multiple middleware functions? (hope this makes sense :-))
You can replace ^:middleware/global
with
^{:middleware/global true
:middleware/global2 true}
Note however that middleware take order based on name. So if order matters, you'll either have to name them in an ordered way, or you have to create your own middleware init-key that combines multiple middlewares in order
Ah thanks - especially about the name order.
I quite like the explicitness of
:routes
{[:get "/foo"]
^:middleware/global
^:middleware/insecure
{[:get "/boo"]
^:middleware/secure
[:middle.handler.middle/index]}}}
I know the example here doesn't make sense but it was just as an illustration.
Do you know if there is a "clojure" or "duct" best practise for this - would it be better to return multiple middleware in the ig/init function definition - my problem with this is that it kind of hides the intent of the EDN.
And I'm not sure how to solve this properly. We use the namespace as a prefix. So
:aaa/middleware1
:bbb/middleware2
etc
Ah right. I must confess I think I prefer reitit to ataraxy so might have a play with that and duct.
All the same thanks very much for your help on this.
There's a duct-reitit implementation, you could take a look at that https://github.com/yannvanhalewyn/duct-reitit
fantastic - I was thinking to myself - how the hell am I going to implement reitit in duct. Perfect!