Skip to content

Commit 01230b5

Browse files
committed
Finish 'Hello World Wide Web' section
1 parent fb1cee7 commit 01230b5

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

index.adoc

+48-1
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ application with Ctrl-C and make a `src` directory.
607607

608608
[,shell]
609609
----
610-
mkdir src
610+
mkdir -p src/todo
611611
----
612612

613613
IMPORTANT: The source directory must be created before running the REPL.
@@ -627,3 +627,50 @@ user=> (go)
627627
:duct.server.http.jetty/starting-server {:port 3000}
628628
:initiated
629629
----
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!

0 commit comments

Comments
 (0)