I have a Clojure app that I can use both from the command-line, and as a Compojure app.
I did that by putting a ring handler and a main function (clojure.tools.cli
) in my leiningen project.clj
.
{...
:main my-app.core
:ring {:handler my-app.handler/handler }}
The handler
is defined (defroutes handler ...)
.
Now if I want to run the CLI app, I can run lein uberjar
and then java -jar arguments
.
And I can also run the Compojure app via lein ring server PORT
.
Now, how do I deploy the thing as a Compojure app (and not a CLI app) in a production server ? (Bonus points for explaining how lein ring server
works.)
Note : I already use nginx if that can help, and I'm flexible on the container to be used.
Here's kind of the default template I use for new projects. It allows you to do dependency injection into ring apps and run the app from the command line as an uberjar. You can read more here: http://www.sparxeng.com/blog/software/improved-clojure-workflow
You can then use leiningen profiles if you need to create multiple apps with different entrypoints from your codebase.