One way around this problem is to create a second (stand-alone) set of routes for your application. You also create a second handler for an individual case. You can then use Leiningen profiles to specify different handlers for the individual case and the uberwar case. The default profile is used when running the application offline. Profile :uberjar used when creating uberwar. As a result, your standalone handler, which will be used with the lein ring server-headless and your regular handler, will be used when the war is deployed to the container.
No additional code is required to create a second set of routes. You can simply wrap existing routes in your chosen context. Suppose your routes and call handler:
(defroutes app-routes (GET "/healthz" [] "Hello World") (route/not-found "Not Found")) (def app (wrap-defaults app-routes site-defaults))
Additional routes and a handler for a particular case will look like this:
(defroutes standalone-routes (context "/myservice" req app-routes) (route/not-found "Not Found")) (def standalone-app (wrap-defaults standalone-routes site-defaults))
Now, on the lein-ring configuration in project.clj . We want the ring handler to point to standalone-app by default. The ring handler for uberwar should point to the app . The entry :ring on the project map in project.clj should look like this (adjust for your actual namespace):
:ring {:handler myservice.handler/standalone-app}
Also, combine the following on a map :profiles in project.clj :
:uberjar {:ring {:handler myservice.handler/app}}
Please use the latest lein-ring plugin. Version 0.9.7 worked for me. Earlier versions, such as 0.8.3, did not work because they did not use the :uberjar profile when running the uberwar task.
If you do all this and assume that your war file is called myservice.war, the context part of the URI will be the same regardless of whether your application is launched using lein ring server-headless or if the war file is deployed to Jetty.
$ curl http://localhost:[port]/myservice/healthz