@@ -270,6 +270,9 @@ $ duct --main --show
270
270
The logging module has been replaced with the `:duct.logger/simple`
271
271
component.
272
272
273
+ NOTE: Data in the configuration file will override data from
274
+ expansions.
275
+
273
276
The `--show` flag also works with the `--repl` command.
274
277
275
278
[,shell]
@@ -733,3 +736,55 @@ user=> (reset)
733
736
734
737
Now when we go access http://localhost:3000/ we find a HTML page
735
738
instead. Congratulations on your first Duct web application!
739
+
740
+ === Routes
741
+
742
+ In the previous section we set up a route and a handler function, but
743
+ you may rightly wonder how the route finds the function.
744
+
745
+ In the <<_fundamentals>> section we learned that key/value pairs in the
746
+ Duct configuration have definitions in the application's source files,
747
+ or from a library.
748
+
749
+ The function we defined was called `todo.routes/index`, and therefore
750
+ we might assume that we'd have a matching key in the configuration.
751
+
752
+ [,clojure]
753
+ ----
754
+ {:todo.routes/index {}}
755
+ ----
756
+
757
+ This component key could then be connected to the routes via a **ref**.
758
+ In other words:
759
+
760
+ [,clojure]
761
+ ----
762
+ {:duct.module/web {:routes [["/" {:get #ig/ref :todo.routes/index}]]}
763
+ :todo.routes/index {}}
764
+ ----
765
+
766
+ And in fact, this is almost exactly what is going on behind the scenes.
767
+
768
+ The Duct web module expands out to a great number of components,
769
+ including a web server, middleware and error handlers, all which can
770
+ be customized. Amongst these components, it creates a **router** and
771
+ a number of **route handlers**.
772
+
773
+ A web module configured the following routes:
774
+
775
+ [,clojure]
776
+ ----
777
+ {:duct.module/web {:routes [["/" {:get :todo.routes/index}]]}}
778
+ ----
779
+
780
+ Will expand out to:
781
+
782
+ [,clojure]
783
+ ----
784
+ {:duct.router/reitit {:routes [["/" {:get #ig/ref :todo.routes/index}]]}
785
+ :todo.routes/index {}}
786
+ ----
787
+
788
+ The router component uses https://github.com/metosin/reitit[Reitit], a
789
+ popular data-driven routing library for Clojure. Other routing libreries
790
+ can be used, but for this documentation we'll assume the default.
0 commit comments