I am learning Clojure Ring. This is my first handler:
(ns long-hdi.core
(:gen-class))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(println "Hello, World!"){:body "hello" :status 200})
(defn on-init[](println "Initializing..."))
(defn on-destroy[](println "destroying..."))
This is the project.clj configuration file:
(defproject long-hdi "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]]
:plugins [[lein-ring "0.9.7"]]
:ring {:handler long-hdi.core/-main :init long-hdi.core/on-init :destroy long-hdi.core/on-destroy}
:main ^:skip-aot long-hdi.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
When I run: lein ring server-headless and browse to http://localhost:3000 I see it prints on the console "Hello, world!" two times. Why does it print 2 times? I suppose it only prints one time only. Then I modify the source code to:
...{:body args :status 200}...
then use Google Chrome to browse to http://localhost:3000 This time, it prints "Hello, world!" 3 times on the console. Why does it change to printing 3 times?
I am using REPL-y 0.3.7, nREPL 0.2.12, Clojure 1.8.0, lein-ring "0.9.7", Windows 10-64 bit.
-main
after you made changes to your code, and theHello, World!
s accumulated on your console. – MicSokoli-main
your handler? You're supposed to use other functions as handlers.-main
should be used only as the entry point to your application. – MicSokoli-main
toother-functions
. Same result. – Long HDi