Can I make lein ring server-headless run on a specific servlet context?
我有一个Ring应用程序,它可以作为
后的上下文中运行
1 2 3 | $ curl -i -X GET http://myservice.qa1.example.com:8080/myservice/healthz HTTP/1.1 200 OK ... |
当我通过lein ring在本地运行时,我需要它在相同的上下文中运行; myservice。
1 2 3 4 | $lein ring server-headless 2015-10-14 14:04:03,457 level=INFO [main] Server:271 - jetty-7.6.13.v20130916 2015-10-14 14:04:03,482 level=INFO [main] AbstractConnector:338 - Started [email protected]:10313 Started server on port 10313 |
但相同的卷曲会在本地将所有404传递给我。
1 2 3 | $ curl -i -X GET http://localhost:10313/myservice/healthz HTTP/1.1 404 Not Found ... |
lein环事物将其部署到根上下文中。
1 2 3 | $ curl -i -X GET http://localhost:10313/healthz HTTP/1.1 200 OK ... |
那是怎么回事?如何引导lein环部署到我选择的上下文名称中?我需要
上工作
解决此问题的一种方法是为您的应用创建第二组(独立)路由。您还为独立案例创建第二个处理程序。然后,您可以使用Leiningen配置文件为独立案例和uberwar案例指定不同的处理程序。独立运行应用程序时使用默认配置文件。创建uberwar时使用
创建第二组路由不需要太多其他代码。您可以将现有路线package在您选择的上下文中。假设以下是您的路由和环形处理程序:
1 2 3 4 5 6 | (defroutes app-routes (GET"/healthz" []"Hello World") (route/not-found"Not Found")) (def app (wrap-defaults app-routes site-defaults)) |
独立案例的其他路由和处理程序如下所示:
1 2 3 4 5 6 | (defroutes standalone-routes (context"/myservice" req app-routes) (route/not-found"Not Found")) (def standalone-app (wrap-defaults standalone-routes site-defaults)) |
现在,进入
1 | :ring {:handler myservice.handler/standalone-app} |
此外,将以下内容合并到
1 | :uberjar {:ring {:handler myservice.handler/app}} |
请确保使用最新版本的
如果您执行所有这些操作,并且假设您的war文件名为myservice.war,则无论您的应用程序是使用
1 | $ curl http://localhost:[port]/myservice/healthz |