File tree 1 file changed +48
-1
lines changed
1 file changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -607,7 +607,7 @@ application with Ctrl-C and make a `src` directory.
607
607
608
608
[,shell]
609
609
----
610
- mkdir src
610
+ mkdir -p src/todo
611
611
----
612
612
613
613
IMPORTANT: The source directory must be created before running the REPL.
@@ -627,3 +627,50 @@ user=> (go)
627
627
:duct.server.http.jetty/starting-server {:port 3000}
628
628
:initiated
629
629
----
630
+
631
+ Clojure has many excellent libraries for writing web applications, but
632
+ it can be difficult to put them all together. Duct's web module handles
633
+ that for you, but like all modules, we can always override any default
634
+ that we don't like.
635
+
636
+ For now, we'll tell the web module to configure the application for use
637
+ as a webside, using the `:site` feature. We'll also add in a single
638
+ route to handle a web request to the root of our application.
639
+
640
+ .duct.edn
641
+ [,clojure]
642
+ ----
643
+ {:vars {jdbc-url {:default "jdbc:sqlite:todo.db"}}
644
+ :system
645
+ {:duct.module/logging {}
646
+ :duct.module/sql {}
647
+ :duct.module/web
648
+ {:features #{:site}
649
+ :routes [["/" {:get :todo.routes/index}]]}}}
650
+ ----
651
+
652
+ Then we'll create a handler function for that route.
653
+
654
+ .src/todo/routes.clj
655
+ [,clojure]
656
+ ----
657
+ (ns todo.routes)
658
+
659
+ (defn index [_options]
660
+ (fn [_request]
661
+ [:html {:lang "en"}
662
+ [:head [:title "Hello World Wide Web"]]
663
+ [:body [:h1 "Hello World Wide Web"]]]))
664
+ ----
665
+
666
+ Finally, we trigger a `(reset)` at the REPL.
667
+
668
+ [,shell]
669
+ ----
670
+ user=> (reset)
671
+ :reloading (todo.routes)
672
+ :resumed
673
+ ----
674
+
675
+ Now when we go access http://localhost:3000/ we find a HTML page
676
+ instead. Congratulations on your first Duct web application!
You can’t perform that action at this time.
0 commit comments